DB Lab3

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

DEPARTMENT OF COMPUTER SCIENCE

( Rachna College of Engineering and Technology Gujranwala )

DATABASE SYSTEMS

Name: Registration No:

LAB 03

Restricting and Sorting Data

Limiting Rows Using a Selection

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;

Note: An alias cannot be used in the WHERE clause


Query: Show all the employees whose department id is 90.
Character Strings and Dates

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 less than 3000.

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.

 % represents any sequence of zero or more characters


 _ represents any single character

Query: Display the employee first name from the EMPLOYEES table for any employee whose
first name begins with the letter S.

Note the uppercase S. Names beginning with an s are not returned.

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_'

Using the NULL Conditions

Query: Return all employees whose manager_id is null.

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

Using the ORDER BY Clause

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.

– ASC: ascending order, default

– DESC: descending order


LAB TASKS

You might also like