Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to except in MySQL

Tags:

sql

mysql

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 support the keyword EXCEPT. Is there a standard mode to use correctly another operator that simulate the except in MySQL?

like image 480
Antonio1996 Avatar asked Oct 22 '17 08:10

Antonio1996


People also ask

Is there except in MySQL?

MySQL does not support the EXCEPT operator.

How do you perform a minus operation in MySQL?

Since MySQL does not provide support for MINUS operator. However, we can use a LEFT JOIN clause to simulate this operator. We can use the following syntax to simulate the MINUS operator: SELECT column_list FROM table1.

Why does MySQL not have intersect?

NOTE: MySQL does not provide support for the INTERSECT operator. This article shows us how to emulate the INTERSECT query in MySQL using the JOIN and IN clause. The following are the rules for a query that uses the INTERSECT operator: The number and order of columns in all the SELECT statements must be the same.


1 Answers

You could use NOT IN

SELECT *  FROM Tab1 WHERE id  NOT IN (     SELECT id      FROM Tab1      WHERE int_attribute_of_Tab1>0 ) 
like image 138
Ben Swinburne Avatar answered Sep 18 '22 23:09

Ben Swinburne