If you have for example > 5 left joins in a query is that a code smell that there is …
- something wrong with your design?
- you’re doing too much in one query?
- you’re database is too normalized?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a perfectly legitimate solution for some designs.
Say you have a hierarchy of one-to-many relations like
Customer–Order–Basket–Item–Price, etc., which can be unfilled on any level: aCustomermay have noOrders, anOrdercan have noBaskets, etc.In this case you issue something like:
Note that it may be inefficient in some cases, and may be replaced with
EXISTSorNOT EXISTS(if you only want to figure out that the corresponding records exist or do not exist in other tables).See this article in my blog for performance details:
LEFT JOIN‘s withNOT EXISTS