MySQL NOT IN from another column in the same table

后端 未结 5 2046
天涯浪人
天涯浪人 2021-02-09 00:32

I want to run a mysql query to select all rows from a table films where the value of the title column does not exist anywhere in all the values of anot

5条回答
  •  -上瘾入骨i
    2021-02-09 01:07

    Try this please:

    • SQLFIDDLE DEMO

    Query:

    select a.id, a.planid
    from one a
    left join one b
    on a.planid <> b.iid
    where not (b.iid is null)
    group by b.id
    ;
    

    Results: based on the sample table I used.

    ID      PLANID
    t15     1
    j18     2
    

    EDIT TO ADD : HERE WITH OP SCHEMA

    select b.id, b.title
    from opschema b
    inner join opschema a
    on b.title <> a.collection
    or b.collection <> a.title
    group by b.id 
    ;
    

    OP SHCEMA SQLFIDDLE DEMO

    ID  TITLE
    2   Film 1
    3   Film 2
    

提交回复
热议问题