Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8050787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:09:26+00:00 2026-06-05T07:09:26+00:00

When I do a left join on a table it duplicates the results from

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:09:27+00:00Added an answer on June 5, 2026 at 7:09 am

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

    SELECT 
         *
    FROM 
        Movie AS M
    WHERE
        EXISTS (SELECT *
          FROM
              MovieImage AS MI
          WHERE  
              M.TheMovieDbId = MI.TheMovieDbId
              AND
              MI.ImageType = 'Poster'
              AND 
              MI.ImageSize = 'Thumb')
    

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

    SELECT 
         *
    FROM 
        Movie AS M
    WHERE
        EXISTS (SELECT *
          FROM
              MovieImage AS MI
          WHERE  
              M.TheMovieDbId = MI.TheMovieDbId
              AND
              MI.ImageType = 'Poster'
              AND 
              MI.ImageSize = 'Thumb')
    UNION
    SELECT * FROM Movie
    

    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)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this equivalent to a LEFT JOIN ? SELECT DISTINCT a.name, b.name FROM tableA
I've seen people writing the following query SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2
Is there a way to avoid adding a second LEFT JOIN for the table
I want to left join 2 tables. So all attributes of left table should
How can I do a join such as : LEFT JOIN table1 t1 ON
My query string is like: SELECT ... FROM maintable LEFT JOIN table1 on (maintable.id
I want to join two tables together and have ONLY the data in Table
Here's my query: $select d.*, count(a.id) as delivered from `dealerships` as d left join
I am LEFT JOINing multiple tables as such: SELECT * FROM table1 LEFT JOIN
I'm trying to LEFT JOIN two tables, to get a list of all rows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.