简体   繁体   中英

Creating a mySQL sub query to list distinct rows from two queries

I have two queries:

'SELECT * FROM `table `WHERE weight = 0 OR weight IS NULL'

and

'SELECT * FROM `table `

The first query returns around 4000 values, the second query returns around 4100.

I'm attempting to create a query that will return the rows which are distinct between the two values, I'm attempting this by using a nested or sub query but I'm struggling with syntax here. Having only worked with very simple queries before. Could anyone suggest how I might do this.

I think this does what you want:

SELECT *
FROM `table`
WHERE NOT (weight = 0 OR weight IS NULL);

That is more simply written as:

SELECT *
FROM `table`
WHERE weight <> 0;

use MINUS operator as below

 SELECT * FROM `table`
 MINUS
 SELECT * FROM `table` WHERE weight = 0 OR weight IS NULL
SELECT * FROM table1 
WHERE (table1.weight = 0 OR table1.weight IS NULL)
AND table1.Column not in (SELECT table2.column
                          FROM table2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM