Scorpion
Scorpion

Reputation: 23

mysql check values from sub query

**** SOLVED ****

SELECT price
FROM inventory
WHERE price > ANY (SELECT price FROM inventory WHERE type = 'new');

Thank you to Mohammed Shafeek and every one else that commented.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I am trying to check if a price is higher than any of the prices in a sub-query.

SELECT price
FROM inventory
WHERE price > price IN (SELECT price FROM inventory WHERE type = 'new');

So I want to be able to check if a price is higher than at least one of the values from the sub-query.

Any help would be much appreciated.

**** EDIT ****

Example of what i mean

$20 > $15, $30, $50

So because $20 is greater than $15 it would be selected

Would this be Min(price)

Like mentioned in below comments

Thanks in advance.

Upvotes: 0

Views: 45

Answers (2)

Mohammedshafeek C S
Mohammedshafeek C S

Reputation: 1943

SELECT price
FROM inventory
WHERE price > ANY (SELECT price FROM inventory WHERE type = 'new');

I think this is the query actually u want.Check it

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269943

One method uses aggregation:

SELECT price
FROM inventory
WHERE price > (SELECT MAX(price) FROM inventory WHERE type = 'new');

Another uses the ALL operator:

SELECT price
FROM inventory
WHERE price > ALL (SELECT price FROM inventory WHERE type = 'new');

Upvotes: 2

Related Questions