SQL CLAUSE

1. WHERE

The WHERE Clause is used to retrieve only those records which fulfill the given criteria.

Syntax:
SELECT column_name
FROM table_name
WHERE conditions;

Example : Query using WHERE clause.
Consider the following table entitled 'Students', which contains information of the students.

Write the Query to find the record of the student where ID = 1.

Student_IDLastNameFirstNameMarks
1PatilRavi60
2MoryaSurendra60
3SinghJaya78
4PanditPrajakta55

SELECT * FROM Students
WHERE Student_ID=1;

The result is shown in the following table.  
       
Student_IDLastNameFirstNameMarks
1PatilRavi60

2. AND

The SQL AND operator is used to combine multiple conditions along with WHERE clause.

Syntax:
SELECT Column_name
FROM table_name
WHERE condition
AND condition;

Example : Query using AND clause.
Consider the following table titled 'Clients'.

1. Write a query to select clients from Pune by using AND clause.

C_IDLastNameFirstNameContact_noCityCountry
1PatilRavi0201234568PuneIndia
2MoryaSurendra0202345677PuneIndia
3SinghJaya0203456788BerlinGermany
4PanditPrajakta0204567897PuneIndia

SELECT C_ID FROM Clients
WHERE City= 'Pune'
AND Country= 'India';

The result is shown in the following table.  

C_ID
1
2
4

2. Write a query to select the information of client from Pune by using AND clause.

SELECT * FROM Clients
WHERE City= 'Pune'
AND Country= 'India';

The result is shown in the following table.   

C_IDLastNameFirstNameContact_noCityCountry
1PatilRavi0201234568PuneIndia
2MoryaSurendra0202345677PuneIndia
4PanditPrajakta0204567897PuneIndia

3. OR

The SQL OR operator is used to combine multiple conditions along with WHERE and OR clause.

Syntax:
SELECT * FROM table_name
WHERE condition
OR condition;

Example : Query using OR clause.
Write the query to select the FirstName from the following table titled  'Clients' by using OR operator.

C_IDLastNameFirstNameContact_noCityCountry
1PatilRavi0201234568PuneIndia
2MoryaSurendra0202345677PuneIndia
3SinghJaya0203456788BerlinGermany
4PanditPrajakta0204567897PuneIndia

SELECT FirstName FROM Clients
WHERE City='Pune'
OR City='Berlin';

The result is shown in the following table.        

FirstName
Ravi
Surendra
Jaya
Prajakta

Write a query to extract data from the following table titled 'Clients' by using OR operator.       

C_IDLastNameFirstNameContact_noCityCountry
1PatilRavi0201234568PuneIndia
2MoryaSurendra0202345677PuneIndia
3SinghJaya0203456788BerlinGermany
4PanditPrajakta0204567897PuneIndia

SELECT * FROM Clients
WHERE Country= 'India'
AND (City= 'Mumbai' OR 'Pune');

The result is shown in the following table.           

C_IDLastNameFirstNameContact_noCityCountry
1PatilRavi0201234568PuneIndia
2MoryaSurendra0202345677PuneIndia
4PanditPrajakta0204567897PuneIndia