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!

Left join for three tables

Status
Not open for further replies.

momen

Technical User
Aug 28, 2003
38
EG
I have three tables:

1-clients:
cli-no
cli-name

2-movies:
mov-no
mov-name

3-bills:
bill-no
cli-no ( fk from clients table)
mov-no ( fk from movies table)

I try to make a query to have this result:
cli-no | cli-name | bill-no | mov-name

For the clients either they has bills or not (null value for clients with no bills)

I tried this:

mysql> select clients.*,bill-no,mov_name
-> from
-> clients left join bills on clients.cli_no=bills.cli_no
-> , movies where bills.mov_no=movies.mov_no;

It gives me data for clients that has bills and not for all the clients.

And this one

mysql> select clients.*,bills.bil_no,movies.movie_name
-> from
-> clients left join bills on
-> clients.cli_no=bills.cli_no
-> movies left join bills on
-> movies.mov_no=bills.mov_no;

I have this error

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near 'movies left join bills on
movies.mov_no=bills.mov_no' at line 5




How can I fix this point?
 
Code:
select clients.*
     , bill-no
     , mov_name
  from clients 
left outer
  join bills 
    on clients.cli_no = bills.cli_no
left outer
  join movies 
    on bills.mov_no = movies.mov_no

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top