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 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-11-17 : 02:25:46
|
| Hi all.. My tables are hereTable 1user_id(primary_key)....name1.....................wilson2....................jafry3...................xxxxxx4...................yyyyyy..100Table2Received_id(primary_key)....user_id10............................111............................2Table 3id(primary_key).......Received_id.....user_id1.........................10...............22.........................10..............33.........................11..............1Now i need my output like thisuser_id(primary_key)....name1.....wilson2.....jafry3......xxxxxI only have Received_id is 10.How to get the output.. Pls help me ! |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2010-11-17 : 03:14:09
|
| [code]SELECT a.User_Id, nameFROM Table1 aJOIN Table2 b ON a.User_Id=b.User_IdWHERE Received_Id = 10[/code]-Chad |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-11-17 : 03:24:26
|
| Tnx chadmat For your reply...I need to select from table 2 & 3 ..Finally from table one for the name |
 |
|
|
chadmat
The Chadinator
1974 Posts |
Posted - 2010-11-17 : 03:28:07
|
| What do you need from Table3?User_id and name are both in Table1, and you want to filter by Received_id which is in Table2. There is no need to involve table3 unless you need something from that table.-Chad |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-11-17 : 03:56:05
|
| Please see my table 3 ..Table 3id(primary_key).......Received_id.....user_id1.........................10...............22.........................10..............33.........................11..............1It also contains one user_id for the received_id.. This row2.........................10..............3from the second table we can't get this value |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-11-17 : 03:58:33
|
| Table 2 & table 3 contains some list of user_id for the given received_id ..We need to select that user_id s.. |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-11-17 : 04:07:04
|
| Then Replace Table2 with Table3 in chadmat's QueryVaibhav TIf I cant go back, I want to go fast... |
 |
|
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-11-17 : 04:48:57
|
| @vaibhavktiwari83 I need to combine both the tables .. table2 and table 3 contains different datas.. after joining these tables need to select the names from table1 .. Pls ask me i you need more info. |
 |
|
|
vaibhavktiwari83
Aged Yak Warrior
843 Posts |
Posted - 2010-11-17 : 05:09:39
|
Try this - SELECT A.UserID, B.Name FROM ( SELECT Distinct a.User_Id FROM Table2 aJOIN Table3 b ON a.Received_id = b.Received_idWHERE Received_Id = 10) A INNER JOIN Table1 B ON A.User_Id = B.User_Id Vaibhav TIf I cant go back, I want to go fast... |
 |
|
|
|
|
|