Het eerste statement in de UNION retourneert vier kolommen:
SELECT b.id AS id,
b.pid AS pid,
b.message AS message,
b.date AS date
FROM wall_posts AS b
De tweede retourneert zes , omdat de * uitbreidt om alle kolommen van WALL_POSTS
te omvatten :
SELECT b.id,
b.date,
b.privacy,
b.pid.
b.uid message
FROM wall_posts AS b
De UNION
en UNION ALL
operators vereisen dat:
- Hetzelfde aantal kolommen bestaat in alle instructies die de UNION-query vormen
- De gegevenstypen moeten overeenkomen op elke positie/kolom
Gebruik:
FROM ((SELECT b.id AS id,
b.pid AS pid,
b.message AS message,
b.date AS date
FROM wall_posts AS b
JOIN Friends AS f ON f.id = b.pid
WHERE f.buddy_id = '1' AND f.status = 'b'
ORDER BY date DESC
LIMIT 0, 10)
UNION
(SELECT id,
pid,
message,
date
FROM wall_posts
WHERE pid = '1'
ORDER BY date DESC
LIMIT 0, 10))