本文介绍了SQL从多个表中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有2个表,我想用一个存储过程从两个表中检索数据。 第二个表有多行链接到一个排在第一桌。 表1 Field 1 Field 2 Field 3 表2 Field 1_1 Field 2_1 Field 3_2 Field 4_2 Field 5_3 Field 6_3 表格通过PK和FK链接 字段1_1,指第二个表字段(字段1)链接到第一个表字段(_1) 我的问题是...我想从单个存储过程查看两个表中的数据,当我执行存储过程时,结果应如下所示: 字段1 - Field 1_1 Field 1 - Field 2_1 Field 2 - Field 3_2 Field 2 - Field 4_2 等等... 到目前为止我尝试了什么...I have 2 tables, I want to retrieve the data from both tables with a single stored procedure.The 2nd table has multiple rows that link to a single row in the 1st table.Table 1Field 1Field 2Field 3Table 2Field 1_1Field 2_1Field 3_2Field 4_2Field 5_3Field 6_3The tables are linked via a PK and FKField 1_1, refers to the 2nd tables field (Field 1) linking to the 1st tables field (_1)My question is ... I would like to view data from both tables from a single stored procedure, when i execute the stored procedure the result should be as follows:Field 1 - Field 1_1Field 1 - Field 2_1Field 2 - Field 3_2Field 2 - Field 4_2etc...What i have tried so far...Create Proc usp_TestAsSelect t1.Field1, t1.Field2, t1.Field3, t2.Field1, t2.Field2, t2.Field3, etcFrom tbl_Table1 t1 right outer join tbl_Table2 t2 on t1.PK = t2.FK 请帮忙......Please help...推荐答案我认为可以通过使用来实现简单INNER JOINI think that can be achieved by using simple INNER JOINSELECTTABLE1_FIELD, TABLE3_FIELDFROM TABLE1INNER JOIN TABLE2 ON TABLE1_FIELD = TABLE2_FIELDCreate Proc usp_TestAsSelect t1.Field1, t1.Field2, t1.Field3, t2.Field1, t2.Field2, t2.Field3, etcFrom tbl_Table1 t1 left outer join tbl_Table2 t2 on t1.PK = t2.FKOrder By t1.Field1 这篇关于SQL从多个表中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-01 18:03