question

sunthea avatar image
sunthea asked

2 simple sql queries - are they identical or not?

Hello Can I replace this query: FROM (SELECT L.LOAN_ID, L.LOAN_NUM, L.PORTFOLIO_ID, L.STS_ID FROM LS_LOAN L WHERE L.PORTFOLIO_ID IN (2, 3)) L2 with this? FROM LS_LOAN L WHERE L.PORTFOLIO_ID IN (2, 3) INNER JOIN L2 ON L2.PORTFOLIO_ID = L.PORTFOLIO_ID Thank you.
sqlsqlquery
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered
Yes, however you have to do the JOIN prior to the WHERE clause. FROM LS_Loan L INNER JOIN LS_Loan L2 on L.Portfolio_ID = L2.Portfolio_ID WHERE L.Portfolio_ID IN (2,3) I suspect the query plans would be different but the results should be the same. Hope that helps!
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.