如何使用联接查询多个表(例如3或4) [英] How to query multiple tables(say 3 or 4) using join

查看:49
本文介绍了如何使用联接查询多个表(例如3或4)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有3张桌子
第一张桌子:
ID用户名地址

第二张表:
productID商品价格

第三桌
ID产品ID


在这里第3个表中,我想获取第一个表和第二个表相对于它们的ID的关系.ny1可以给我打电话如何查询它吗?

suppose I hv 3 tables
1st table:
ID UserName Address

2nd Table:
productID Items Price

3rd table
ID productID


here 3rd table I want to get the relation of the first and 2nd table with respect to their ID''s.. Can ny1 tel me how to query it???

推荐答案

pl检查以下文章/帖子:


http://msdn.microsoft.com/en-us/library/ms191430 (v = SQL.100).aspx [ http://stackoverflow.com/questions/693327/sql-how-to-join-多个表 [ ^ ]
pl check the following articles/posts:


http://msdn.microsoft.com/en-us/library/ms191430(v=SQL.100).aspx[^]


http://stackoverflow.com/questions/693327/sql-how-to-join-multiple-tables[^]


如果您是初学者,想在自己的作品中获得帮助,这是另一种解决方案:

打开Sql Server Management Studio并连接到DB.单击 new query ,然后右键单击新打开的窗口,然后选择Design query in editor.
通过使用该向导,可以将所需的任何表添加到查询设计器中,并将一个表字段拖到另一表字段中,可以在特定字段上应用联接.
如果它们具有相关的外键,它将自动创建JOIN语句.

尝试研究那些自动创建的JOIN,以学习如何联接两个表.
并查看以下资源:
http: //beyondrelational.com/blogs/nakul/archive/2011/07/14/ssms-query-designer-ad-hoc-query-writing-editing-made-simple.aspx [ http://devguru.com/technologies/t-sql/7114.asp [ ^ ]

http://www.sql-tutorial.net/SQL-JOIN.asp [ ^ ]

希望对您有所帮助.
If you are a beginner and want to get help in your works here is another solution :

Open Sql Server Management Studio and connect to a DB. the click on new query then right click on the newly opened window then select Design query in editor.
By using that wizard you can add any table that you want to the query designer and by dragging one table field to another table field you can apply joins on specific field.
If they have related foreign keys it automatically creates JOIN statements.

Try to study those auto created JOINs to learn how to join two table.
And also have a look at these resources :
http://beyondrelational.com/blogs/nakul/archive/2011/07/14/ssms-query-designer-ad-hoc-query-writing-editing-made-simple.aspx[^]

http://devguru.com/technologies/t-sql/7114.asp[^]

http://www.sql-tutorial.net/SQL-JOIN.asp[^]

Hope it helps.


select id,productid,username,address,items,price from 1sttable,2ndtable,3rdtable where id.1sttable=id.3rdtable and productid.2ndtable=productidtable



我认为这可能对您有帮助...这是非ascci



i think this may help u... and this is non-ascci


这篇关于如何使用联接查询多个表(例如3或4)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆