Salut à tous,
J'ai un petit problème dans une jointure...
But: sélectionner des utilisateurs (t1) ayant une information (t2) liée à un nom (t3). Exemple:
t1> a.id = 12t2> s.mdta = 1223920t3> c.name = roman
L'information data_likes doit être aléatoire et non null.
La voilà:
Et MySQL me répond : champ a.id inconnu... J'imagine que le select du left join ne permet pas de récupérer l'information a.id... Une idée comment faire?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 SELECT a.id, s.mdta, c.name FROM t1 a LEFT JOIN ( SELECT o.user_id, o.data AS mdta FROM t2 o WHERE o.user_id = a.id ORDER BY rand() LIMIT 1 ) s ON a.id = s.user_id LEFT JOIN t3 c ON s.mdta = c.page_id WHERE s.mdta IS NOT NULL
Merci.
EDIT: résolu, le rand() va quand même changer mon résultat en GROUP BY... étonnamment...
Partager