SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col1 = t2.id where t2.col2 ='1'
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col2 = t2.id where t2.col1 ='1'
我可以在单个查询中合并两个查询吗?我尝试使用WHEN THEN!
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col1 = t2.id where t2.col2 ='1'
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col2 = t2.id where t2.col1 ='1'
我可以在单个查询中合并两个查询吗?我尝试使用WHEN THEN!
怎么样UNION
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col1 = t2.id where t2.col2 ='1'
UNION
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col2 = t2.id where t2.col1 ='1'
听起来你想要
SELECT col1, col2
FROM (
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col1 = t2.id where t2.col2 ='1'
UNION
SELECT col1,col2 FROM t1 INNER JOIN t2 ON t1.col2 = t2.id where t2.col1 ='1'
)
ORDER BY whatever
SELECT col1,col2 FROM t1, t2
WHERE
(t1.col1 = t2.id AND t2.col2 = '1')
OR
(t1.col2 = t2.id AND t2.col1 = '1')
是另一种方式。但UNION
也应该真的有效。