Why do multiple-table joins produce duplicate rows?

前端 未结 4 1510

Let\'s say I have three tables A, B, and C. Each has two columns: a primary key and some other piece of data. They each have the same number of rows. If I JOIN

4条回答
  •  孤独总比滥情好
    2020-12-24 12:02

    Ok in this example you are getting duplicates because you are joining both D and S onto M. I assume you should be joining D.id onto S.id like below:

    SELECT *
    FROM M
    INNER JOIN S
        on M.Id = S.Id
    INNER JOIN D
        ON S.Id = D.Id
    INNER JOIN H
        ON D.Id = H.Id
    

提交回复
热议问题