Den første sætning i UNION returnerer fire kolonner:
SELECT b.id AS id,
b.pid AS pid,
b.message AS message,
b.date AS date
FROM wall_posts AS b
Den anden returnerer seks , fordi * udvides til at inkludere alle kolonnerne fra WALL_POSTS
:
SELECT b.id,
b.date,
b.privacy,
b.pid.
b.uid message
FROM wall_posts AS b
UNION
og UNION ALL
operatører kræver, at:
- Det samme antal kolonner findes i alle de udsagn, der udgør UNION-forespørgslen
- Datatyperne skal matche ved hver position/kolonne
Brug:
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))