Loading ...

IN SQL, AND clause is used when we apply more than one condition with WHERE clause. | CodeAsp.Net

AND & OR Operator in SQL

 /5
0 (0votes)

We use AND & OR operator in SQL when Where clause requeries more than one conditions.
IN SQL, AND clause is used when we apply  more than one condition with WHERE clause,
and it gives the results when all given contions are true i.e all conditions to be true.
Following is the Structure of the table:

Create Table users
(
FirstName varchar(50),
City varchar(50)
)
Insert into users (FirstName,City) values('vikas','Noida')
Insert into users (FirstName,City) values('vijendra','Delhi')
Insert into users (FirstName,City) values('singh','Mumbai')
Insert into users (FirstName,City) values('vijendra','Mainpuri')
Select * from users Where FirstName='vijendra' AND City='Delhi'

This query returns following results:

FirstName        City
vijendra         Delhi
Select * from users Where FirstName='vijendra' AND City='Noida'

This query returns No records.

In SQL OR clause is used similar to the AND clause only and main difference is it returns all rows in which any one condition is true.
i.e. OR returns a record if any one condition is true.

Select * from users Where FirstName='vijendra' OR City='Delhi'

This query returns following results:

FirstName        City
vijendra         Delhi
vijendra         Mainpuri
Select * from users Where FirstName='vijendra' OR City='Noida'

This query returns following results:

FirstName        City
vijendra         Delhi
vijendra         Mainpuri
vikas            Noida

Comments (no comments yet)

  • :*
  • :*
  • :
 *

Top Posts