sql server - Duplicate Rows on SQL Join -


when left join on table duplicates results left table when more values found in right table. how can return distinct values left when there multiple values on right table. (return 1 movie when there multiple images on right table)

select       *      movie m     left join movieimage mi (nolock) on m.themoviedbid = mi.themoviedbid       mi.imagetype = 'poster' , mi.imagesize = 'thumb' or mi.imagetype null 

typically, wouldn't use "right table" if don't want results it.

select       *      movie m     exists (select *                 movieimage mi                   m.themoviedbid = mi.themoviedbid           ,           mi.imagetype = 'poster'           ,            mi.imagesize = 'thumb') 

to have rows no rows match (as per query), use this

select       *      movie m     exists (select *                 movieimage mi                   m.themoviedbid = mi.themoviedbid           ,           mi.imagetype = 'poster'           ,            mi.imagesize = 'thumb') union select * movie 

otherwise, saying "give me arbitrary row movieimage" never understand...

other notes:

  • don't use nolock time
  • qualify table names schema name (typically dbo)

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -