0

Is this a correct way of doing two left joins? What I want is that the last left join should NOT have a "filtering" effect on the first left join, i.e. the result set with the two left joins should have at least an equal number of rows as only the first left join produces.

select a.uc_id, cr.imei,cr.points,log.start,log.end
from routes cr 
left join assets a on a.imei = cr.imei
left join logistics log on a.uc_id=log.uc_id
analyst92
  • 243
  • 1
  • 6
  • 1
    Do you mean to say you tried this query and it did not work the way you wanted? How was it different? It should not be so hard to create a test case with 1 record in `routes` than joins to a record in `assets`, 1 that does not, and 1 record in `asset` that joins to a record in `logistics` and 1 that does not, then explain what was unexpected. See [How do I ask a good question?] – Atmo Mar 05 '23 at 12:45
  • This is unclear. What does 'have a "filtering" effect on the first left join' mean? Left join has a definition, it does that, what do you think that is, quoting an authoritative reference, and what are you trying to do, and is that it or not, etc? How could the last left join not "have at least an equal number of rows as only the first left join produces", since it's a left join? [ask] [Help] Debug questions require a [mre]. PS Putting words in scare quotes does not clarify the idiosyncratic meaning that you don't make clear by actually saying what you mean. – philipxy Mar 05 '23 at 13:39
  • [What is the difference between "INNER JOIN" and "OUTER JOIN"?](https://stackoverflow.com/a/46091641/3404097) [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/3404097) – philipxy Mar 05 '23 at 13:42

1 Answers1

1

You are right, this is the right way. This is true:

...the result set with the two left joins should have at least an equal number of rows as only the first left join produces.

The result set with two left joins would have at least an equal number of rows as only the first left join produces.

M. Hicks
  • 76
  • 3
  • 7