user3855329
user3855329

Reputation: 77

Query with JOIN on multiple tables

I have this little query that is working fine:

SELECT * FROM Components AS T1
WHERE Cost=null or Cost=''
Order by Code

Now I need to grab also the filed "description" from other tables where code=code

SELECT * FROM Components AS T1
WHERE Cost=null or Cost=''

LEFT JOIN on Table_321 AS T2
where T1.Code=T2.Code

Order by Code

But it is giving me a sintax error around "LEFT" which I have not been able to solve and I am not sure if such JOIN is the correct way to get it. Some help indicating me the how to solve the problem will be really appreciated. Moreover, I have also another table "Table_621 from which I need to take the description. How can I add this second table in the query?

Upvotes: 0

Views: 59

Answers (3)

JasonS
JasonS

Reputation: 199

SELECT * FROM Components AS T1
LEFT JOIN Table_321 AS T2
ON T1.Code=T2.Code
WHERE Cost=null or Cost=''

Order by Code

Upvotes: 0

fortune
fortune

Reputation: 3372

SELECT * FROM Components T1
LEFT JOIN Table_321 T2 ON T1.Code=T2.Code
LEFT JOIN Table3 T3 ON T3.Code = T1.Code
WHERE T1.Cost=null or T1.Cost=''
ORDER BY T1.Code

Upvotes: 1

vhadalgi
vhadalgi

Reputation: 7189

Order by is ambiguous In below case:

SELECT * FROM Components T1
    LEFT JOIN Table_321 T2
    ON T1.Code=T2.Code
    WHERE T1.Cost=null or T1.Cost=''
    ORDER BY Code

try like this

SELECT * FROM Components T1
        LEFT JOIN Table_321 T2
        ON T1.Code=T2.Code
        WHERE T1.Cost=null or T1.Cost=''
        ORDER BY T2.Code --or T1.Code

Upvotes: 0

Related Questions