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)