No question is too basic! I am a SQL expert busy asking very basic Java Script questions. You may as well ask directly rather than get frustrated trying to make sense of what you can find on the web, and as long as you are making an effort then everyone is happy.
What you have asked for is in fact not basic at all and could be interpreted in many ways. A few different SQL's will give you a few different results.
Firstly, this part:
WHERE table1.name NOT LIKE 'test'
It's unusual to use LIKE without wildcard characters (%, _). If you want to exclude records that are exactly 'test' then don't use like, use this instead:
WHERE table1.name <> 'test'
<> means 'different to'
With regards, to outer joining the next table in, firstly, are you certain you want to outer join it in?
You might be after this code, although this is not exactly what you have asked for:
SELECT table1.name, table2.city AS city, table2.province
FROM table1 LEFT OUTER JOIN table2
ON table1.id = table2.id
LEFT OUTER JOIN table3
ON table1.id = table3.id
WHERE table1.name NOT LIKE 'test'
ORDER BY city DESC
This is of course missing this bit:
AND table2.city = city
In this case are you trying to match the column city to the literal string 'city' or are you trying to match to the column city? if so, is the column in table1 or table2
There are slightly different ways of intepereting your question which in turn mean writing different SQL, which in turn gives you a different answer.
So have a think about this:
- Is there always a matching record in table2 against table1? if so you can use INNER JOIN instead of OUTER JOIN and save some complications
- You should draw a diagram of your tables with lines showing how they are connected.
Also if you give a less generic name for the tables it helps us visualise what you are trying to do.