MYSQL returning duplicate rows

后端 未结 3 924
生来不讨喜
生来不讨喜 2021-01-16 10:57

I have a Database table in MYSQL, it looks like this:

Project_ID  user_ID  name
11          1        fred
11          2        rick
11          1        fred         


        
3条回答
  •  借酒劲吻你
    2021-01-16 11:33

    Point 1 is that should the user be assigned to the project twice?

    Point 2 - Use the DISTINCT keyword to return only unique records - http://dev.mysql.com/doc/refman/5.0/en/distinct-optimization.html

    SELECT DISTINCT user_ID
    FROM TABLE
    WHERE Project_id = 11
    

    That will return you 1 and 2 (You won't get 1 twice)

    Thanks

提交回复
热议问题