0% found this document useful (0 votes)
78 views4 pages

SELECT With Various Clause - WHERE, Pattern Matching

The document discusses various clauses used in the SELECT statement in SQL including WHERE, LIKE, BETWEEN, IN, and aggregate functions. It provides the syntax and examples of how to use each clause. It lists 10 questions about using the WHERE clause with conditions, patterns, ranges, and sets. It then lists 7 additional questions about using the BETWEEN, IN, and aggregate function clauses in SELECT statements.

Uploaded by

mahima 008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views4 pages

SELECT With Various Clause - WHERE, Pattern Matching

The document discusses various clauses used in the SELECT statement in SQL including WHERE, LIKE, BETWEEN, IN, and aggregate functions. It provides the syntax and examples of how to use each clause. It lists 10 questions about using the WHERE clause with conditions, patterns, ranges, and sets. It then lists 7 additional questions about using the BETWEEN, IN, and aggregate function clauses in SELECT statements.

Uploaded by

mahima 008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ex. No.

: 4
Date:
SELECT with various clause – WHERE, pattern matching

AIM:

To view the records from the tables using SELECT commands with
WHERE Clause and Pattern matching.

DESCRIPTION:

The SELECT statement allows you to get the data from tables. A table consists of
rows and columns like a spreadsheet. Often, you want to see a subset rows, a subset of
columns, or a combination of two. The result of the SELECT statement is called a result
set that is a list of rows, each consisting of the same number of columns.

SYNTAX:

SELECT:

SELECT
column_1, column_2, ...
FROM
table_1
[INNER | LEFT |RIGHT] JOIN table_2 ON conditions
WHERE
conditions
GROUP BY column_1
HAVING group_conditions
ORDER BY column_1
LIMIT offset, length;

The SELECT statement consists of several clauses as explained in the following list:

 SELECT followed by a list of comma-separated columns or an asterisk (*)


 to indicate that you want to return all columns.
 FROM specifies the table or view where you want to query the data. 
  JOIN gets related data from other tables based on specific join conditions. 
  WHERE clause filters row in the result set.
 GROUP BY clause groups a set of rows into groups and applies aggregate
 functions on each group.
  HAVING clause filters group based on groups defined by GROUP BY clause.
 ORDER BY clause specifies a list of columns for sorting.
 LIMIT constrains the number of returned rows.

11 | P a g e
CS016-DATABASE MANAGEMENT SYSTEMS

LIKE:

The LIKE operator is commonly used to select data based on patterns. Using
the LIKE operator in the right way is essential to increase the query performance.

The LIKE operator allows you to select data from a table based on a specified
pattern. Therefore, the LIKE operator is often used in the WHERE clause of
the SELECT statement.

MySQL provides two wildcard characters for using with the LIKE operator,
the percentage % and underscore _ .

 The percentage ( % ) wildcard allows you to match any string of zero or


 more characters.
 The underscore ( _ ) wildcard allows you to match any single character. 

Questions:

WHERE:

1. The student counsellor wanted to display the registration number,


student name and date of birth for all the students.
2. The controller of examinations wanted to list all the female students
3. Who are the boy students registered for course with the course number “C001“
4. Display all faculty details joined before “November 2014”
5. Display all the courses not allotted to halls

LIKE:
6. List the students whose name ends with the substring “ma”
7. Display all students whose name contains the substring “ma”
8. Find all the students who are located in cities having “Sal” as substring
9. Display the students whose names do not contain six letters.
10. Find all the students whose names contains “th”

Ex. No. : 5
Date:

SELECT with various clause – BETWEEN, IN, Aggregate function

AIM:

To view the records from the tables using SELECT commands with
BETWEEN, IN, Aggregate functions.
DESCRIPTION:

The BETWEEN operator allows you to specify a range to test. We often use the
BETWEEN operator in the WHERE clause of the SELECT, INSERT,
UPDATE, and DELETE statements.

The IN operator allows you to determine if a specified value matches any one of a
list or a sub query.

MySQL provides many aggregate functions that include AVG, COUNT, SUM,
MIN, MAX, etc. An aggregate function ignores NULL values when it performs
calculation except for the COUNT function.

SYNTAX:

BETWEEN operator:

SELECT
column1,column2,...
FROM
table_name
WHERE expr [NOT] BETWEEN begin_expr AND end_expr;

The expr is the expression to test in the range that is defined by


begin_expr and end_expr.

IN operator:

SELECT
column1,column2,...
FROM
table_name
WHERE (expr|column_1) IN ('value1','value2',...);

13 | P a g e
CS016-DATABASE MANAGEMENT SYSTEMS

Questions:

IN & BETWEEN

1. List the type of the courses “Statistics” and “Programming”


2. The instructor wants to know the CourseNos whose scores are in the range
50
to 80

AGGREGATE

1. Find the average mark of “C002”.


2. List the maximum, minimum mark for “C021”
th
3. List the maximum, minimum, average mark for each subject in 5 semester
4. List the name of the courses and average mark of each courses.
5. Calculate the sum of all the scores.
6. How many students are registered for each course? Display the
course description and the number of students registered in each course.
7. How many courses did each student register for? Use Assessment table.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy