Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8918907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:52:10+00:00 2026-06-15T05:52:10+00:00

I have 4 tables. Im trying to get the max value for each car

  • 0

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

enter image description here

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: enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:52:11+00:00Added an answer on June 15, 2026 at 5:52 am

    Your joining would be fine if you wanted only the maximum vehicle price per brand. It would need only a GROUP BY and the MAX() function (notice that you don’t need the Class table for this):

    SELECT B.BRAND_NAME, 
           MAX(V.VEH_PRICE) AS MAX_VEH_PRICE
    
    FROM ( VEHICLE V
      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_ID, B.BRAND_NAME ;
    

    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:

    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
        )
    
      INNER JOIN
    
        ( SELECT M.BRAND_ID, 
                 MAX(V.VEH_PRICE) AS VEH_PRICE  
          FROM (VEHICLE V
            INNER JOIN MODEL M ON M.MODEL_ID = V.MODEL_ID)
          GROUP BY M.BRAND_ID 
        ) AS derived
    
        ON  b.BRAND_ID = derived.BRAND_ID
        AND v.VEH_PRICE = derived.VEH_PRICE ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two tables i am trying to get information from. login table -
I have two tables: hotels and hotel_rooms I'm trying to get a table with
I have a 3 tables that I'm trying to join and get distinct results.
I have a table with users and are trying to get a list with
I have the below table. I am trying to get tbody column bgcolors matching
Table #1: qa_returns_items Table #2: qa_returns_residues I have a long time trying to get
I am trying use gem tire to search in my application. I have tables
I have multiple tables in a mysql database and I am trying to put
I have two tables as shown here . I am trying to fetch name
I have several tables that I am selecting data from. I am trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.