这是我遇到的问题的简化版本,
我有两张桌子:
Table1 has two columns (Stuff, YesNo) and
Table2 has one column (Stuff)
YesNo列中的记录将为1或0
如何在Table2中选择Table1.YesNo = 1
中记录的记录非常感谢
答案 0 :(得分:1)
SELECT Table2.*
FROM Table2
INNER JOIN Table1 ON Table1.Stuff = Table2.Stuff
WHERE Table1.YesNo = 1
答案 1 :(得分:0)
如果我理解正确,这将是您的解决方案:
Select Stuff From Table2
Where Exists (
Select 'Y'
From Table1
Where Table1.Stuff = Table2.Stuff
And YesNo = 1
)
答案 2 :(得分:0)
我相信您需要来自两个表的数据,并且您可能希望呈现每个表唯一的字段这似乎是一个可能的响应。但是,由于我不相信STUFF准确地表示了这种关系......您需要量化/调整on a.stuff = b.stuff
,以便联接包括所有必要的字段。
SELECT A.Stuff, B.Stuff, B.YesNo
FROM table1 B
INNER JOIN table2 A
on A.Stuff = B.Stuff
WHERE B.YesNo = 1
答案 3 :(得分:0)
SELECT T2.*
FROM TABLE1 T1
JOIN TABLE2 T2
ON T1.Stuff = T2.Stuff
WHERE T1.YesNo = 1