选择具有一个公共列的多个表的查询 [英] Select query for Multiple tables with one Common Column

查看:80
本文介绍了选择具有一个公共列的多个表的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多个表的选择查询,其中包含一个公共列



i已经尝试过以下但不能正常工作







a select query for Multiple tables with one Common Column

i have tried something below but not working



Select *  from DM_Audit da,  DM_APPLICANTS dap , DM_POLICY dp, DM_Names dn,DM_Address ad 
where da.fk_applicationID=dap.fk_applicationID and
dap.fk_applicationID=dp.fk_applicationID and 
dp.fk_applicationID=dn.fk_applicationID and
dn.fk_applicationID=ad.fk_applicationID 





这里fk_applicationID是所有表中的公共列



Sql新手请帮助



Here fk_applicationID is Common column in all the table

New to the Sql Please Help

推荐答案

Select *  from DM_Audit as da,  DM_APPLICANTS as dap , DM_POLICY as dp, DM_Names as dn,DM_Address as ad
where da.fk_applicationID=dap.fk_applicationID and
da.fk_applicationID=dp.fk_applicationID and
da.fk_applicationID=dn.fk_applicationID and
da.fk_applicationID=ad.fk_applicationID


尝试创建一个视图,然后非常清楚,在创建视图后,您的查询将自动创建
Try to Create a View then its very much clear and after creating view your query will automatically created


列名可能相同,但它是否为每个表中的预定记录?



如果确实如此,那么使用连接重新编写查询将是检查链接的更简单方法:



The column name may be the same, but does it reference data for the intended records in each table?

If it definitely does, then re-writing the query using joins would be an easier way of checking the links:

Select *  
from DM_Audit da  
INNER JOIN DM_APPLICANTS dap ON dap.fk_applicationID=da.fk_applicationID



等........

在这种情况下我通常会有一个'关键'表(即其中包含大部分数据,或链接到大多数其他需要加入的表格的数据)然后加入其他表格要容易得多。



N.B.如果不是所有表都加入到密钥表中,请尽可能多地加入,然后在语句的下方加入已加入表。


etc........
I would usually have a 'key' table in this situation (i.e. with the most data in it, or one which links to the most other tables which need to be joined) Then it is much easier to join the other tables.

N.B. if not all tables join to the key table, join as many as you can first, then join to the 'joined' tables further down the statement.


这篇关于选择具有一个公共列的多个表的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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