DB Lab3
DB Lab3
DB Lab3
DATABASE SYSTEMS
LAB 03
You can restrict the rows that are returned from the query by using the WHERE clause. A
WHERE clause contains a condition that must be met, and it directly follows the FROM clause.
If the condition is true, the row meeting the condition is returned. The syntax of query with a
where clause is as follows;
Character strings and date values are enclosed by single quotation marks. Character values are
case-sensitive, and date values are format-sensitive. The default date format is DD-MON-RR.
Comparison Conditions
Comparison Operators are = , < , > , <= , >= , <>, like , between and , in , is null
Query: List all employees whose salary is between 2500 and 3000
Query: Displays employee numbers, last names, salaries, and manager’s employee numbers for
all the employees whose manager’s employee number is 100, 101, or 201.
You can select rows that match a character pattern by using the LIKE condition.
Query: Display the employee first name from the EMPLOYEES table for any employee whose
first name begins with the letter S.
Query: Return all records from employees table those have "O" as second latter in last_name
What you will do if your search string itself contain _ or %. You can use the ESCAPE identifier
to search for the actual % and _ symbols.
Query: Write a query that return all employee whose job id contains 'SA_'
Logical Conditions
You can add more than one selection statements using AND,OR and NOT.
Query: Display only those employees who have a job title that contains the string ‘MAN’ and
earn $10,000 or more.
Query: Return all employees those are not 'IT_Prog', 'ST_CLERK' and
'SA_REP'
Rules of precedence in case of multiple conditions
Order by clause is used to sort the data. It always come at the end of select statement. You can
use alias in order by clause.