Wednesday 19 September 2007

Explain AND & OR conditions in SQL Server.

The AND & OR is used to join two or more conditions in a WHERE clause.

The AND operator displays a row if ALL the conditions listed are true.

Ex :
Select * from Employees
where EmployeeName = ‘Steve’
and City = ‘Bangalore

This Query will display the each person with EmployeeName equal to “Steve” and City equal to “Bangalore

The OR operator displays a row if ANY of the conditions listed are true

Ex :
Select * from Employees
where EmployeeName = ‘Steve’
or City = ‘Bangalore

This Query will display the each person with EmployeeName equal to “Steve” or City equal to “Bangalore”.

Labels: ,


Bookmark this Blog in your Favorites

Monday 10 September 2007

What is the difference between UNION and UNIONALL commands in SQLServer?

The UNION command is used to select the related data from two different tables, while using the UNION command all the selected columns have to to be of the same data type.

Ex :
Select EmployeeName from Employees
union
Select EmployeeName from Department

This Query will display only the distinct Employee names in Employees and Department Tables.

The UNION ALL command is similar to UNION command, but it displays all the values in the both the tables.

Ex :
Select EmployeeName from Employees
union all
Select EmployeeName from Department

This Query will display all the Employee names in Employees and Department Tables.

Labels: ,


Bookmark this Blog in your Favorites