MySQL Join Same Table

前端 未结 3 464
离开以前
离开以前 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条回答
  •  半阙折子戏
    2020-12-29 08:34

    Make an outer (left) join to itself, filtering on those records that don't match by looking for rows with a null id in the joined table:

    select t1.* 
    from meta_data t1
    left join meta_data t2 on t2.post_id = t1.post_id and t2.meta_key='def' 
    where t1.meta_key='abc'
    and t2.id is null
    

提交回复
热议问题