0

我正在使用这三个表,我想要table3详细信息table_1.field_id。现在我得到了没有table_1.field_id. 如何包含table1.field_idwithtable_3记录?

询问:

select 
   fld_id, fld_name, fld_date 
from 
   table_3
where 
   fld_item_id in (select fld_id 
                   from tbl_table2 
                   where fld_cust_id in (select fld_id 
                                         from table_1 
                                         where fld_ref_id = 100));

表 3

FLD_ID FLD_Name FLD_DATE     FLD_ITEM_ID
101       hai   12-01-2013   10

表 2

FLD_ID FLD_value FLD_CUST_ID  FLD_DATE     
10       100     10000        12-01-2013

表 1

FLD_ID FLD_NAME fld_ref_id  FLD_DATE
10000  Vinoth   100         12-01-2013
4

1 回答 1

2

尝试(由 RBarryYoung 建议)

SELECT B.fld_cust_id Table1FieldId, C.fld_id, C.fld_name, C.fld_date 
FROM tbl_table2 B
INNER JOIN table_3 C ON C.fld_item_id = B.fld_id
WHERE A.fld_ref_id=100

或(如果您需要其他字段table_1

SELECT A.fld_id Table1FieldId, C.fld_id, C.fld_name, C.fld_date 
FROM table_1 A
INNER JOIN tbl_table2 B ON B.fld_cust_id = A.fld_id 
INNER JOIN table_3 C ON C.fld_item_id = B.fld_id
WHERE A.fld_ref_id=100
于 2013-04-28T14:00:49.760 回答