Ms-access – MAX and MIN for each car model

functionsgroup byjoin;ms-access-2010

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?

Best Answer

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;