MySQL LEFT JOIN duplicates results

前端 未结 2 2039
暗喜
暗喜 2020-12-11 05:37

I have a problem with implementing a module where one project can belong to multiple categories. Example: project \"PHP Programmer\" belongs to cat

2条回答
  •  心在旅途
    2020-12-11 06:24

    You can also rewrite this as an "IN" to get around duplicates:

    SELECT projects.*
    FROM projects      
    where projects.id in (select project_id
                          from projects_category
                          WHERE pojects_category.category_id IN (1,3,11)
                         ) and
          projects.id='94'
    

    The "in" prevents duplicates from forming when you are using joins for filtering records.

提交回复
热议问题