Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JOIN 3 tables

Status
Not open for further replies.

Quasibobo

Programmer
Oct 11, 2001
168
NL
Hi,

I'm trying to join 3 tables, but all I get is a MySQL-syntax error:

The tables:
losmomenten{id (int), user_id(int), los_datum(date), los_time(time), afzender(int),dock(int)}
afzenders {afzender(int), bedrijf(varchar), plaats(varchar), land(varchar)}
users {user_id(int), naam(varchar), plaats(varchar)}

Now I'd like to select almost everthing out of these 3 tables (an export to xls-file) in one query:
Code:
$select = "SELECT losmomenten.*, afzenders.*, users.* FROM losmomenten RIGHT JOIN afzenders,users ON losmomenten.afzender=afzenders.afzender, losmomenten.user_id=users.user_id WHERE losmomenten.user_id='$user' AND losmomenten.los_datum='$export_datum' ORDER BY losmomenten.dock,losmomenten.los_time";

What am I doing wrong?

Don't eat yellow snow!
 
i think this is what you want:

[tt]select losmomenten.*
, afzenders.*
, users.*
from losmomenten
left outer
join afzenders
on losmomenten.user_id=users.user_id
left outer
join users
on losmomenten.afzender=afzenders.afzender
where losmomenten.user_id='$user'
and losmomenten.los_datum='$export_datum'
order
by losmomenten.dock
, losmomenten.los_time[/tt]

rudy
SQL Consulting
 
Ok... thanks, I'll have a go with that!

Don't eat yellow snow!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top