La première instruction de l'UNION renvoie quatre colonnes :
SELECT b.id AS id,
b.pid AS pid,
b.message AS message,
b.date AS date
FROM wall_posts AS b
Le second renvoie six , car le * se développe pour inclure toutes les colonnes de WALL_POSTS
:
SELECT b.id,
b.date,
b.privacy,
b.pid.
b.uid message
FROM wall_posts AS b
L'UNION
et UNION ALL
les opérateurs exigent que :
- Le même nombre de colonnes existe dans toutes les instructions qui composent la requête UNION'd
- Les types de données doivent correspondre à chaque position/colonne
Utiliser :
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))