JTC
JTC

Reputation: 3464

Exclude rows with specific columns values from SELECT

I've got table with following columns and data:

stock   quant
-----   -----
10      0
10     -5
10      1
1       20
10      1
10      88
5       1

What I need is to exclude rows with stock_status = 10 and quantity <= 0 at the same time.

I need to have those rows with stock_status = 10 but quantity > 0 or the other way around.

So the desire output from this would be

stock   quant
----    ---
10      1
1       20
10      1
10      88
5       1

Thanks.

Upvotes: 3

Views: 3114

Answers (2)

Jean-Fran&#231;ois Savard
Jean-Fran&#231;ois Savard

Reputation: 21004

Well you actually wrote the query yourself by telling us what you need to exclude...

SELECT stock, quant
FROM yourTable 
WHERE NOT(stock_status = 10 AND quantity <= 0); 

You should follow a tutorial on SQL query (for example on W3school) as this is very basic and you should be able to do a query like that in less than a minute after following a very short tutorial for beginner.

I recommend this link : SQL Tutorial.

Upvotes: 10

Barmar
Barmar

Reputation: 780673

SELECT stock, quant
FROM yourTable
WHERE NOT (stock_status = 10 AND quantity <= 0)

or, apply de Morgan's Laws:

SELECT stock, quant
FROM yourTable
WHERE stock_status != 10 OR quantity > 0

Upvotes: 3

Related Questions