MySQL Forums
Forum List  »  PHP

Re: Problem with SQL query :(
Posted by: Rick James
Date: January 22, 2014 04:19PM

> the only result I get is the same as before which isnt right, or syntax error..

The word, or punctuation, at, or immediately before, the quoted string is almost always the token that is 'wrong'.

> What comes after the ON ? Or how is this build, I dont understand it how to make multiple JOINS, one I could make but how I do one in another one ?

The pattern:

The ON clause 'ties' the tables together.

SELECT ... FROM table1 AS a
JOIN table2 AS b ON b.foo = a.foo
JOIN table3 AS c ON c.blah = b.blah

table1, table2, table3 -- these are usually different tables. However in your schema, table2 and table3 are likely to both be your Properties table.

b.foo = a.foo -- "foo" is whatever field ties the two tables together. Sometimes it is
b.manufacturer_id = a.id -- if "a" is the Manufacturer table;
b.this = a.this AND b.that = b.that -- if they are tied on two fields.

c.blah = b.blah -- Usually the third table is tied to the second, but not necessarily; it could be
c.blah = a.blah

The WHERE clause (which comes after all the JOINs) specifies any further filtering you need on the data. Sometimes it does not matter whether this stuff is in the WHERE or in the ON; it is a good idea to "tie via ON; filter via WHERE".

Sorry, I don't have a list of SQL manuals from which to learn the basics.

Options: ReplyQuote


Subject
Written By
Posted
January 18, 2014 10:39PM
January 19, 2014 12:30PM
January 19, 2014 12:41PM
January 20, 2014 03:24PM
January 21, 2014 06:22PM
Re: Problem with SQL query :(
January 22, 2014 04:19PM
January 23, 2014 12:15AM
January 23, 2014 10:23AM
January 19, 2014 12:33PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.