JOIN和 和有什么不一样UNION?我可以举个例子吗?
JOIN
UNION
UNION将查询中的行放在一起,同时JOIN制作笛卡尔积并将其子集——完全不同的操作。的简单示例UNION:
mysql> SELECT 23 AS bah -> UNION -> SELECT 45 AS bah; +-----+ | bah | +-----+ | 23 | | 45 | +-----+ 2 rows in set (0.00 sec)
类似的简单示例JOIN:
mysql> SELECT * FROM -> (SELECT 23 AS bah) AS foo -> JOIN -> (SELECT 45 AS bah) AS bar -> ON (33=33); +-----+-----+ | foo | bar | +-----+-----+ | 23 | 45 | +-----+-----+ 1 row in set (0.01 sec)