Professional Documents
Culture Documents
The BETWEEN operator selects values within a given range. The values
can be numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end values are included.
The BETWEEN operator returns TRUE if a value is in a
range of values:
5) USING MYSQL WHERE CLAUSE WITH THE
LIKE OPERATOR EXAMPLE
Example : Write an SQL query that will display the items or products
with ‘er’ at last
To form a pattern, you use the % and _ wildcards. The % wildcard matches any string of zero or
more characters while the _ wildcard matches any single character.
6) USING MYSQL WHERE CLAUSE WITH THE IN
OPERATOR EXAMPLE
Syntax:
Select from table_name
where column_name
operator value
INTRODUCTION TO THE MYSQL
ORDER BY CLAUSE
When you use the SELECT statement to query data
from a table, the order of rows in the result set is
unspecified. To sort the rows in the result set, you add
the ORDER BY clause to the SELECT statement.
In this syntax, you specify the one or more columns
that you want to sort after the ORDER BY clause
A) Using MySQL ORDER BY clause to sort the
result set by one column example
B) Using MySQL ORDER BY clause to sort the
result set by multiple columns example
If you want to sort the customers by the last name in descending order and then
by the first name in ascending order, you specify both DESC and ASC in these
respective columns as follows:
C) Using MySQL ORDER BY clause to sort a
result set by an expression example
The following query selects the order line items from the item1 table. It calculates the
subtotal for each line item and sorts the result set based on the subtotal.
Before we do that one let us add first column Name Quantity and insert the following
data
An employer creates a record for his employees whose names and details are listed below
EmployeeID EmployeeName Address Salary
1001 Manny Atienza Bulacan 3000
1002 Ferdinand Duterte Manila 2000
1003 Eleonor Pangilinan Naga 4000
1004 Lenny Moreno Makati 5000
a. After several months, he wants to find out whose employee has a salary of 4,000 above.
b. He wants also to know whose employee that is in between Manny Atienza and Lenny Moreno
c. After finding such records, he wants also to know whose employee that’s is in between 1002 and
1004 and employee id that is not in 1001.
After a few months another batch of employee was hired:
EmployeeID EmployeeName Address Salary
1005 Sailor Mooned Cotabato 10000
1006 Dorathy Explorer Roxas 12000
1007 Dorae Moon Gensan 7000
d. Since there were so many records the employer wants to know those names start with the letter D
e. Also, those names ended with “ny”.
c. He wants also to know whose records with the “A” character on them.
d. Lastly find an address that has 6 characters of length