Skip to content
Advertisement

Left Join Where Clause (name matching ID from another table)

I want to the output to be the birthday, first and last name of customers who have been served by David who has the employee ID of 1. But for some reason (and it may be obvious, im only a beginner), it only outputs one row of Victor who’s c_id matches e_id (which I know the clue is somewhere there but can’t figure out).

How do I get this to work?

Advertisement

Answer

EXISTS is a much better way to express this:

Notes:

  • The JOIN conditions are now correct, using c_id (although in this version, the conditions are in a correlation clause.
  • You do not need SELECT DISTINCT, because no duplicates are created when “David” has served someone more than once. This is a big performance win.
  • e_id is a number, so the comparison should be to a number (1) not to a string ('1').
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement