Page 1 of 1

JOIN

Posted: Tue Oct 02, 2007 1:45 am
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.

Posted: Tue Oct 02, 2007 9:56 am
by feyd
Because you're using an implicit inner join, either should be fine.

Re: JOIN

Posted: Tue Oct 02, 2007 11:29 am
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.