0% found this document useful (0 votes)
36 views2 pages

2021 - 08 - 27 Tutorial 02

The document discusses the SELECT query in SQL and how to use it to fetch records from a database table. It explains how to select all fields or particular fields and how to add WHERE clauses to filter results by conditions, lists, or ranges.

Uploaded by

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

2021 - 08 - 27 Tutorial 02

The document discusses the SELECT query in SQL and how to use it to fetch records from a database table. It explains how to select all fields or particular fields and how to add WHERE clauses to filter results by conditions, lists, or ranges.

Uploaded by

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

AID-523 Database Systems

Tutorial 02 August 27th , 2021

Tutorial Session
• SELECT query is used to fetch records from database. * is used to select all fields/columns:

SELECT * FROM tablename;

SELECT * FROM cats;

• SELECT query for particular fields:

SELECT fieldname_1, fieldname_2, ..., fieldname_n FROM tablename;

SELECT id, name FROM cats;

• Format of SELECT query with WHERE clause:

SELECT fieldname FROM tablename WHERE condition;

SELECT id, name FROM cats WHERE birth<‘2016-01-01’;

• Format of SELECT query with WHERE clause and multiple conditions:

SELECT fieldname FROM tablename


WHERE condition_1 [AND/OR] condition_2, ..., condition_n;

SELECT * FROM cats WHERE birth<‘2016-01-01’ AND birth>‘2014-01-01’;

• Format of SELECT query with WHERE clause and a list:

SELECT fieldname FROM tablename


WHERE condition_1 [IN/NOT IN] (a, ..., b);

SELECT * FROM cats WHERE owner IN (‘Lennon’, ‘Casey’);

SELECT * FROM cats WHERE id NOT IN (1, 5, 6, 7);

• Format of SELECT query with WHERE clause and a range (inclusive):

SELECT fieldname FROM tablename


WHERE fieldname BETWEEN a AND b;

SELECT * FROM cats WHERE id BETWEEN 2 AND 100;

......................................................................................................

1
WHERE is an optional clause. It specifies the condition that returned the matched records in the result
set.

Operator Description Example


= Checks if the values of the two operands are equal or not, if yes, (A = B) is not true.
then the condition becomes true.
! = or <> Checks if the values of the two operands are equal or not, if the (A ! = B) is true.
values are not equal then the condition becomes true.
> Checks if the value of the left operand is greater than the value (A > B) is not true.
of the right operand, if yes, then the condition becomes true.
< Checks if the value of the left operand is less than the value of the (A < B) is true.
right operand, if yes then the condition becomes true.
>= Checks if the value of the left operand is greater than or equal to (A >= B) is not true.
the value of the right operand, if yes, then the condition becomes
true.
<= Checks if the value of the left operand is less than or equal to (A <= B) is true.
the value of the right operand, if yes, then the condition becomes
true.

......................................................................................................

You might also like