UNION与交叉表where子句

时间:2016-11-13 17:25:03

标签: mysql

(SELECT *, 0 AS user FROM table1) 
UNION 
(SELECT * FROM table2 WHERE unix >= {$threemonths}) 
ORDER BY unix DESC;

我需要添加:

WHERE table2.identifier = table1.identifier或其他什么

我希望从table1获取所有内容,并且只有来自table2 identifier table1identifierelse的{​​{1}}行。< / p>

2 个答案:

答案 0 :(得分:2)

请查看这是否适合您

(SELECT *, 0 AS user FROM table1) 
UNION 
(SELECT * FROM table2 WHERE unix >= {$threemonths} and exists (select 'Y' from table1 a where a.identifier = table2.identifier)) 
ORDER BY unix DESC;

答案 1 :(得分:0)

可能是

{{1}}