Nasty MySQL statements 
Just found out how to do a LEFT JOIN on combined tables with UNION. It's a bit tricky, but the point is that the result of a UNION is another table... See below:

SELECT `ID`, "whatever columns" FROM (
SELECT "whatever" FROM t1
UNION DISTINCT
SELECT "whatever" FROM t2
) AS newName1
LEFT JOIN
(
SELECT `ID` FROM t3
UNION DISTINCT
SELECT `ID` FROM t4
) AS newName2
ON `newName1`.`ID` = `newName2`.`ID` WHERE `newName2`.`ID` IS NOT NULL


Welcome 
Hi all,

This is my attempt to blog whatever I'm doing. Most likely it will contain nothing useful and maybe at some point everything will be just canned, but I thought it might be a good idea to start something, so I can just spit my struggles with computing somewhere ;)

Eduard


Back