JOIN

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
devnetworkphp
Forum Newbie
Posts: 3
Joined: Tue Oct 02, 2007 1:35 am

JOIN

Post by devnetworkphp »

I am newb to sql.

tables

contact
contact_id
contact_name

orders
order_id
contact_id

Which one is right for the table?

Code: Select all

SELECT * FROM contact, orders WHERE contact.contact_id=orders.order_id

  SELECT * FROM contact, orders WHERE orders.order_id=contact.contact_id
i think both are correct as i am comparing and not assigning.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Because you're using an implicit inner join, either should be fine.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: JOIN

Post by califdon »

devnetworkphp wrote:

Code: Select all

  SELECT * FROM contact, orders WHERE contact.contact_id=orders.order_id

  SELECT * FROM contact, orders WHERE orders.order_id=contact.contact_id
Think of it this way: The part that comes after the WHERE key word is simply a conditional statement, either it evaluates as true (include the row) or false (don't include the row). So the order doesn't matter.
Post Reply