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 |
|
akki1563
Starting Member
10 Posts |
Posted - 2012-02-06 : 07:46:05
|
| Hi,I have 4 tables Which are independent of each other. But there is one column u_id which is common to all tables which is not primary key nor foreign key. how do i write select statement which should get records where u_id is same in all 4 tablesPlease suggestRegards,Akki |
|
|
Mehala
Starting Member
7 Posts |
Posted - 2012-02-06 : 08:04:25
|
| U can use union to display all records.Meks |
 |
|
|
akki1563
Starting Member
10 Posts |
Posted - 2012-02-06 : 08:17:59
|
Hi Mehala,Table 1 Table1column1 - PkTable1column2 Table3column3u_id Table 2 Table2column1 - PkTable2column2 Table2column3u_idTable 3 Table3column1 - PkTable3column2 Table3column3u_idTable 4Table4column1 - PkTable4column2 Table4column3u_idIn the above 4 tables u_id is common column. suppose u_id has value 100 in all 4 tables i need fetch those rows from all 4 tables whichhas u_id as 100. How can i do that ?I tried Select * from Table1 t1, Table2 t2, Table3 t3, Table4 t4where t1.u_id=t2.u_id=t3_uidBut this is wrong. I am new to sql programming . can u help me outHow to use union on this ?Regards,Akki quote: Originally posted by Mehala U can use union to display all records.Meks
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-06 : 09:21:13
|
| [code]Select * from Table1 t1inner join Table2 t2on t1.u_id=t2.u_idinner join Table3 t3on t3.u_id=t2.u_idinner join Table4 t4on t4.u_id=t3.u_id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|