如何基于在另一个表中过滤的列来过滤列?

时间:2020-04-10 08:13:41

标签: sql

我是SQL的新手,感谢您在以下方面的帮助:

我想根据在另一个表中过滤的列来过滤列

SELECT *
FROM TableX 
WHERE ColumnX IN (ColX distinct values of TableY, where ColumnZ in ('a','b',c'))

4 个答案:

答案 0 :(得分:3)

您可以使用join:

console.log("data type : " + typeof(data));

但是,您也可以使用select x.* from tablex x inner join tabley y on y.colx = x.colx where y.colz in ('a', 'b', 'c');

exists

答案 1 :(得分:0)

SELECT * 
FROM TableX 
where ColumnX in (select y.ColX from TableY as y where y.ColumnZ in ('a','b','c'))

答案 2 :(得分:0)

这是您想要的正确语法:

SELECT * FROM TableX 
WHERE ColumnX IN (
  SELECT DISTINCT ColX FROM TableY 
  WHERE ColumnZ IN ('a','b','c')
)

答案 3 :(得分:0)

select * 
from tableX 
where columnX in (
         select 
            colX 
         from tableY 
         where columnZ in ('a','b','c')
   )