I have 4 tables. Im trying to get the max value for each car brand. There are 10 BRANDS. Im trying to get which car is the most expensive for each brand.
The first thing i did was group all the tables from where I wanted to get information.
I’ve join tables BRAND, MODEL, CLASS, AND VEH. I’m not really sure how to get the max for each group however.
SELECT B.BRAND_NAME, M.MODEL_NAME, C.CLASS_NAME, V.VEH_YEAR, V.VEH_PRICE
FROM ((VEHICLE V INNER JOIN CLASS C ON V.CLASS_ID = C.CLASS_ID)
INNER JOIN MODEL M ON M.MODEL_ID = V.MODEL_ID)
INNER JOIN BRAND B ON B.BRAND_ID = M.BRAND_ID

I tried:
SELECT B.BRAND_NAME, M.MODEL_NAME, C.CLASS_NAME, V.VEH_YEAR, V.VEH_PRICE
FROM (
SELECT B.BRAND_NAME, MAX(V.VEH_PRICE)
FROM ((VEHICLE V INNER JOIN CLASS C ON V.CLASS_ID = C.CLASS_ID)
INNER JOIN MODEL M ON M.MODEL_ID = V.MODEL_ID)
INNER JOIN BRAND B ON B.BRAND_ID = M.BRAND_ID
GROUP BY B.BRAND_NAME
);
Im getting: 
Your joining would be fine if you wanted only the maximum vehicle price per brand. It would need only a
GROUP BYand theMAX()function (notice that you don’t need theClasstable for this):To get all the vehicles’ data for those vehicles that have the maximum price, you need to write the previous query in a subquery ( a derived table) and then join again: