2014-03-02 22 views
-1

我是sql中的新手。我想要使​​用连接两个表的结果。我想在sql中使用多个select命令

这里有详细信息。

表1(usertb)

id username password fname lname 
--------------------------------- 
1 amit  abc111 amit ganatra 
2 rakesh r111  rakesh patel 
3 sanajay s111  sanjay Mor 

表2(好友列表)

id fid 
-------- 
1  2 
1  3 

这意味着ID NO 1具有两个朋友的IDNO是1和2,当在记录有ID = 1的用户应该是好友列表,

2 rakesh patel 
3 sanjay Mor 
+0

[演出相结合的各种表格的数据(http://stackoverflow.com/questions/22144335/show-combined-data-of-various-tables)的可能重复的 - 没有必要重复你的自己的问题。 – hakre

回答

0

它被称为连接。

Select t1.fname, t1.lname From table1 t1 
inner join table2 t2 on t2.fid = t1.id 
Where t2.id = 1 

一对sql课程会很好地支持你,停止你正在做的事情并采取一个。

+0

谢谢...它解决了我的查询..谢谢很多tony – user3370745

0
Select table2.fid, tabel1.fname + table1.lname 
from table1 innerjoin table2 on table2.fid = table1.id 
+0

谢谢安杰洛...它帮助了我很多...再次感谢 – user3370745

+0

你可以投票并标记为已回答 – Angelo