0

I have a query which looks like

SELECT * FROM mytable mt
WHERE 1=1
AND mt.column_1 IN (SELECT id FROM employee WHERE salary >10000)
OR  mt.column_2 IN (SELECT id FROM employee WHERE salary >10000)

I know the above query is not looking good even though it is getting my job done. I did google but could not find help. The reason I ask is the actual scenario the 'employee' table is temp table which is filled with data at the upper levels of the strored_procedure and this particular is my final select statement for the procedure.

1 Answer 1

2

I think a simple JOIN would do the trick

SELECT mt.* 
 FROM mytable mt
 JOIN (SELECT id FROM employee WHERE salary >10000) B
   on mt.column_1=B.ID or mt.column_2=B.ID 
Sign up to request clarification or add additional context in comments.

Comments

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.