Thursday, November 24, 2011

how to select data from multiple tables in sql server

Title:How to retrieve the data from set of tables in SQL server

Description:
As per recent articles we have seen how to get the data from single table in SQL server.Now i want explain the same concept with multiple tables.The SQLserver has provided a Keyword which is used to get data from set of  tables using SQL query i:e"INTERSECT" keyword.Here i will show to get empid ,name from employee table by comparing with empid column in Department table

SELECT empid, name FROM Employee
WHERE empid IN
SELECT empid FROM Employee INTERSECT SELECT empid FROM Department) 
Here i have shown one more query to get the data from different table with out join
SELECT em.empid,em.name FROM Employee em,Department de WHERE em.empid=de.empid 

No comments:

Bel