We can combined AND, OR, and NOT Conditions in where clause. And
and OR Condition are used to retrieve data using multiple conditions
·
And Condition shows data if condition is divide by and in where
clause
- OR condition retrieve
rows if conditions are divided by OR
- Not Condition
shows a data if condition is not true
AND Query
SELECT * FROM your_table_name WHERE condition_1 AND condition _2 AND condition_3;
OR Query
SELECT * FROM your_table_name
WHERE condition_1 OR condition_2 OR condition_3;
NOT Syntax
SELECT * FROM your_table_name WHERE NOT condition;
Well this was the syntax now will show you some examples of And,
OR and NOT
Example AND Condition
The Following query returns all rows where “FirstName” is “Nancy” and “LastName” is “Davolio”
Select * From [Employees] where
FirstName='Nancy' and LastName='Davolio';
Example OR Condition
Following query
returns all rows where TitleOfCourtesy is 'Mr.' or 'Ms.'
Select *
From [Employees] where
TitleOfCourtesy='Mr.'
or TitleOfCourtesy='Ms.';
NOT Example
Following query
return rows where Title is not 'Sales Manager’
Select *
From [Employees] where
not Title= 'Sales Manager' ;
Combining AND, OR and NOT Conditions
We can combine the AND, OR and NOT conditions.
Following SQL query selects rows where city is "London" AND Title must be "'Sales Manager " OR
"'Sales Representative”
Select * From [Employees] where city= 'London' and (Title ='Sales Manager' or Title='Sales Representative' );
Comments
Post a Comment