SQL query producing unwanted duplicate rows in result

后端 未结 2 1131
醉酒成梦
醉酒成梦 2021-01-29 02:42

I\'m wrangling with a rather simple query. However, given my low level of Access and SQL competency, I\'ve hit a roadblock with my current project. Details are below and thank y

相关标签:
2条回答
  • 2021-01-29 03:09

    try using the argument distinct, which will remove duplicate values.

    0 讨论(0)
  • 2021-01-29 03:19

    When you are joining the tables that have both the company ID [CUSIP] and the year [4DTYR] you are only joining on [CUSIP], so you are getting duplicate rows for the various permutations of [4DTYR] in the related tables that also have that field. You need to join on both [CUSIP] and [4DTYR] to avoid those duplicates.

    In Access' query designer such joins will appear as two lines running between each table: one connecting [CUSIP] to [CUSIP] and the other connecting [4DTYR] to [4DTYR]. In SQL the joins will look something like

    ... TableX LEFT JOIN TableY ON TableX.CUSIP = TableY.CUSIP AND TableX.4DTYR = TableY.4DTYR
    
    0 讨论(0)
提交回复
热议问题