Skip to content
Advertisement

Duplicate Rows on SQL Join

When I do a left join on a table it duplicates the results from the left table when more values are found in the right table. How can I only return the distinct values from the left even when there are multiple values on the right table. (return only the one movie even when there are multiple images on the right table)

Advertisement

Answer

Typically, you wouldn’t use a “right table” if you don’t want results from it.

To have rows where no rows match too (as per your query), use this

Otherwise, you are saying “give me an arbitrary row from MovieImage” which I never understand…

Other notes:

  • don’t use NOLOCK all the time
  • qualify your table names with schema name (typically dbo)
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement