MySQL Join Same Table

前端 未结 3 460
离开以前
离开以前 2020-12-29 07:49

I have the table \'meta_data\' with the following fields:

  • id
  • post_id
  • meta_key
  • meta_value

I\'d like to loop throug

3条回答
  •  梦毁少年i
    2020-12-29 08:17

    To achieve this you should use the LEFT OUTER JOIN operation joining the same table.

    SELECT a.*
    FROM meta_data a
    LEFT OUTER JOIN meta_data b ON a.post_id = b.post_id AND b.meta_value = 'def'
    WHERE 
    a.meta_value = 'abc'
    AND b.post_id IS null
    

提交回复
热议问题