0% found this document useful (0 votes)
4 views18 pages

Lecture 29

This document provides an overview of SQL query syntax, including the SELECT statement, WHERE clause, and various operators such as NOT, BETWEEN, IN, and LIKE. It includes examples demonstrating how to use these operators to filter and retrieve data from a database. Additionally, it explains the ORDER BY clause for sorting query results.

Uploaded by

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

Lecture 29

This document provides an overview of SQL query syntax, including the SELECT statement, WHERE clause, and various operators such as NOT, BETWEEN, IN, and LIKE. It includes examples demonstrating how to use these operators to filter and retrieve data from a database. Additionally, it explains the ORDER BY clause for sorting query results.

Uploaded by

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

Database

Management
System

Lecture - 29
Where: Format
SELECT [ALL|DISTINCT]
{*|culumn_list [alias][,…..n]}
FROM table_name
[WHERE <search_condition>]
< search_condition > ::=
{ [ NOT ] < predicate > | ( < search_condition > ) }
[ { AND | OR } [ NOT ] { < predicate > |
( < search_condition > ) } ]
} [ ,...n ]
< predicate > ::=
{ expression { = | < > | ! = | > | > = | ! > | < | < = | ! < }
expression
| string_expression [ NOT ] LIKE string_expression
| expression [ NOT ] BETWEEN expression AND
expression
| expression IS [ NOT ] NULL
| expression [ NOT ] IN ( subquery | expression [ ,...n ] )

| expression { = | < > | ! = | > | > = | ! > | < | < = | ! < }


{ ALL | SOME | ANY} ( subquery )
| EXISTS ( subquery )
}
Where Example
Q: Display all courses of the MCS
program
Select crCode, crName, prName
from course
where prName = ‘MCS’
Not Operator
Inverses the predicate’s value
Q: List the course names offered to
programs other than MCS
SELECT crCode, crName, prName
FROM course
WHERE not (prName = ‘MCS’)
SELECT crCode, crName, prName
FROM course
WHERE (prName != ‘MCS’)
The BETWEEN Operator
Checks the value in a range
Q: List the IDs of the students with course
codes having marks between 70 and 80
SELECT stId, crCode, totMrks
From ENROLL
WHERE totMrks between 70 and 80
The IN Operator
Checks in a list of values
Q: Give the course names of MCS and
BCS programs
SELECT crName, prName
From course
Where prName in (‘MCS’, ‘BCS’)
SELECT crName, prName
From course
Where (prName = ‘MCS’) OR
(prName = ‘BCS’)
Like Operator
Q: Display the names and credits of
CS programs
SELECT crName, crCrdts, prName
FROM course
WHERE prName like '%CS'
“Order By” Clause
Sorts the rows in a particular order
SELECT select_list
FROM table_source
[ WHERE search_condition ]
[ ORDER BY order_expression [ ASC | DESC ]
[,……n]
]
Database
Management
System

Lecture - 29

You might also like