Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
dhinasql
Posting Yak Master
195 Posts |
Posted - 2013-05-07 : 16:06:55
|
I have two table, Table1:DepId DepName1 CSE2. IT3. MECHTable2:StudID Name DepID1 ABC 12 XYZ 13 QWE 24 OPI 1I want to display the Department Name from Table 1 if that is exist in Table 2Expected ResultDEPNAMECSEITThere is No student available for Mech in Table2 so it should not disply in result. |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2013-05-07 : 16:12:08
|
SELECT DepNameFROM Table1 t1WHERE t1.DepID in (SELECT DISTINCT DepID FROM Table2)-Chad |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-08 : 00:14:43
|
[code]SELECT DepNameFROM Table1 t1WHERE EXISTS (SELECT 1 FROM table2 WHERE DepID = t1.ID)[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
|
|
|