我有这个简单的查询
SELECT * from switch_person where PTPK = (
SELECT PK from projects where TeamLead = 1 and status = 1)
它正确显示了swith_person
列。另外,我想显示projects
表格列。
子查询表“projects
”包括我要显示的列和switch_person
列。这可能吗?
答案 0 :(得分:2)
使用join代替子查询:
SELECT *
from switch_person
join project on PTPK = PK
where TeamLead = 1 and status = 1
答案 1 :(得分:2)
为了选择多个列,连接到派生表而不是使用子查询,然后您可以选择多个派生表列:
SELECT x.PK, x.Col1, x.Col2, ...
from switch_person
INNER JOIN
(
SELECT PK, Col1, Col2
FROM projects
WHERE TeamLead = 1 and status = 1
) x
ON PTPK = x.PK;