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.