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

我需要添加:聯合與交叉表where子句

WHERE table2.identifier = table1.identifier什麼

我想從那裏identifier在結果中發現從table1「從table2table1只有行獲得所有s identifier列。

回答

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; 
0

可能是

SELECT *, 0 AS user FROM table1 
    UNION 
    SELECT * FROM table2 WHERE unix >= {$threemonths} 
    INNER JOIN table1 on table2.identifier = table1.identifier 
    ORDER BY unix DESC;