Share via

which select to use

arkiboys 9,711 Reputation points
2024-02-07T07:15:33.69+00:00

can you let me know which of the below sql is best to use and why? As you see I can either use lines 2 and 3 or just use line 5 instead. So is it best to use lines 2 and 3 or just line 5? thanks User's image

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


Answer accepted by question author

LiHongMSFT-4306 31,621 Reputation points
2024-02-07T08:58:28.9066667+00:00

Hi @arkiboys

which select to use

We do not know your tables or what result you want.

If both of them return same result, then why not test by yourself?

I could only give you some theoretical suggestions, like:

  • Avoid too many OR conditions. Try to rewrite where clause by removing unnecessary conditions or changing to use a function such as case or decode.
  • Find out any possible to change from hash join to EXISTS.
  • Check the execution plan and see if any chance to improve.

Best regards,

Cosmog Hong


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

1 additional answer

Sort by: Most helpful
  1. arkiboys 9,711 Reputation points
    2024-02-08T05:39:10.1466667+00:00

    I am not using any specific tables for my queries above. Over time I have seen some developers use one method and others use the other method. Therefor I wonder what the difference of the two is as they both look like giving doing the same thing and I would like to learn about their comparison as to which is best to use. Thank you

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.