0

I have two tables T1 and T2

T1
-id
-columnA
-columnB
-columnC

T2
-id
-columnX
-columnY
-columnZ

I have a query like

Select t1.* t2.columnZ 
from T1 t1 
  left join on T2 t2 on t1.id = t2.id 
where t2.columnZ = 'test'

I want result like if "where t2.columnZ = 'test'" does not return any row then it should return value of columnZ as null value

1
  • can you explain what the output you required ? Commented Dec 22, 2015 at 11:13

1 Answer 1

3

Try:

SELECT    t1.*
,         t2.columnZ
FROM      T1 t1
LEFT JOIN T2 t2 
       ON t1.id = t2.id
      AND t2.columnZ = 'test'

You also missed a comma, and you had a misplaced on.

Sign up to request clarification or add additional context in comments.

1 Comment

@wingedpanther, I replaced the original where with and, with where selects only those that have 'test'. The question, as I understood it, is to get a complete set, some may have 'test' others not. I also don't get your edit, what was the point?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.