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)
SELECT
*
FROM
Movie AS M
LEFT JOIN MovieImage AS MI WITH (
NOLOCK
) ON M.TheMovieDbId = MI.TheMovieDbId
WHERE
MI.ImageType = 'Poster'
AND MI.ImageSize = 'Thumb'
OR MI.ImageType IS NULL
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: