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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mysql query join syntax

Status
Not open for further replies.

andrewlivi

IS-IT--Management
Feb 8, 2005
1
US
I want to join the 2 tables so that I can link 2 sets of fields.

Current script:

$query = "SELECT movie_name, people_fullname
FROM movie
LEFT JOIN people
ON movie_leadactor = people_id
ORDER BY movie_name";

What I want to do:

$query = "SELECT movie_name, people_fullname
FROM movie
LEFT JOIN people
ON movie_leadactor = people_id and movie_director = people_id
ORDER BY movie_name";

I'm sure the solution is easy. I just don't know what it is. Thanks for your help.
 
Cant you use a natural join for this?

Code:
$query = "SELECT movie_name, people_fullname
    FROM movie, people 
    WHERE movie_leadactor = people_id AND movie_director = people_id
    ORDER BY movie_name";

ps. I might have mis-understood your fieldtypes.

Olav Alexander Mjelde
Admin & Webmaster
 
i nearly always cheat in these circumstances by creating a new access project and linking to the mysql database, then using the query builder to do the first cut of the sql code with the joins etc.

but then I'm lazy.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top