2013-01-04 4 views
0

J'ai ce problème.Joindre à gauche en utilisant une condition

je dois obtenir ces champs de ma table de correspondance:

date, points 

Alors j'ai un champ epos_id aussi bien dans ma table de correspondance ..

J'ai une autre table rbpos_epos qui a epos_id et location champ.

J'ai besoin pour obtenir le location du rbpos_epos avec des jointures .. quelque chose comme ceci:

SELECT matching.date, matching.points, matching.time,matching.location,matching.epos_id,rbpos_epos.epos_id,rbpos_epos.location 
FROM matching WHERE matching.user_id="'.$id_user.'" 
LEFT JOIN rbpos_epos where matching.epos_id=rbpos_epos.epos_id; 

Répondre

0
SELECT 
    first_table.date, 
    first_table.points, 
    first_table.time, 
    first_table.location, 
    first_table.epos_id, 
    rbpos_epos.epos_id, 
    rbpos_epos.location 
FROM 
    first_table 
LEFT JOIN 
    rbpos_epos ON first_table.epos_id = rbpos_epos.epos_id 
WHERE 
    first_table.user_id = "'.$id_user.'"; 
+0

Cela fonctionne oui, mais je ne comprends pas l'emplacement maintenant .. –

+0

'rbpos_epos' est-ce que l'emplacement est occupé? – Sahal

+0

OUI, IL FAIT !!! –

0

Utilisez le lieu où -

SELECT matching.date, matching.points, matching.time,matching.location,matching.epos_id,rbpos_epos.epos_id,rbpos_epos.location 
    FROM matching LEFT JOIN rbpos_epos ON matching.epos_id=rbpos_epos.epos_id  
     WHERE matching.user_id="'.$id_user.'"; 
+0

Je reçois "requête était vide" .. –

+0

Qu'est-ce que c'est? copier coller ? – Sahal

0

Essayez ceci:

SELECT m.date, m.points, m.time,m.location,m.epos_id,re.epos_id,re.location 
FROM matching m 
LEFT JOIN rbpos_epos re ON m.epos_id=re.epos_id 
WHERE m.user_id= 10 
+0

La requête était vide .. encore! –

+1

Quel est le problème. Ajouter des exemples de données de table –