SELECT With Various Clause - WHERE, Pattern Matching
SELECT With Various Clause - WHERE, Pattern Matching
: 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:
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 _ .
Questions:
WHERE:
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:
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;
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
AGGREGATE