Alternative to except in MySQL

前端 未结 3 1796
谎友^
谎友^ 2021-02-07 04:53

I must write a Query like this in MySQL:

SELECT * 
FROM Tab1
EXCEPT
SELECT * 
FROM Tab1 
WHERE int_attribute_of_Tab1>0

but MySQL doesn\'t su

相关标签:
3条回答
  • 2021-02-07 05:02

    You could use NOT IN

    SELECT * 
    FROM Tab1
    WHERE id  NOT IN (
        SELECT id 
        FROM Tab1 
        WHERE int_attribute_of_Tab1>0
    )
    
    0 讨论(0)
  • 2021-02-07 05:21

    Try this

    SELECT * 
    FROM Tab1
    WHERE [....] NOT EXISTS 
    (SELECT * 
    FROM Tab1 
    WHERE int_attribute_of_Tab1>0) 
    
    0 讨论(0)
  • 2021-02-07 05:24

    A couple of definitions SqlServer https://docs.microsoft.com/en-us/sql/t-sql/language-elements/set-operators-except-and-intersect-transact-sql EXCEPT Returns any distinct values from the query to the left of the EXCEPT operator that are not also returned from the right query. PLsql https://docs.oracle.com/cd/B19306_01/server.102/b14200/queries004.htm MINUS statement combines results with the MINUS operator, which returns only unique rows returned by the first query but not by the second

    A pedantic translation to mysql would be

     SELECT distinct t1.* 
    FROM Tab1 as t1
    left outer join
    (SELECT * 
    FROM Tab1 
    WHERE int_attribute_of_Tab1>0) as t2 on t1.id = t2.id
    where t2.id is null;
    

    Assuming there is an id column, And I wouldn't like to use distinct on a lot of columns.

    0 讨论(0)
提交回复
热议问题