2

I have a problem with a query. I have a db with car and their spec, every model has a different car related to that model with its price. I want to create a query that gives me the min and max price for each models.

something like this:

+--------+----------+
| model  | price    |
+--------+----------+
| golf   | 4000     | 
| golf   | 6000     |
| golf   | 10000    | 
| panda  | 3000     | 
| panda  | 5000     |
| panda  | 7000     |
+--------+----------+

the query give me this:

+--------+----------+
| model  | price    |
+--------+----------+
| golf   | 4000     | 
| golf   | 10000    | 
| panda  | 3000     | 
| panda  | 7000     |
+--------+----------+

Can you help me?

6

You can simple use UNION ALL:

SELECT model, MIN(price) price
FROM YourTable
GROUP BY model
UNION ALL
SELECT model, MAX(price) price
FROM YourTable
GROUP BY model;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.