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

  • Home
  • SEARCH
  • 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 4070234
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:36:05+00:00 2026-05-20T16:36:05+00:00

OK I tried googling for an answer like crazy, but I couldn’t resolve this,

  • 0

OK I tried googling for an answer like crazy, but I couldn’t resolve this, so I hope someone will be able to help.

Let’s say I have a table of users, very simple table:

id | userName
3    Michael
4    Mike
5    George

and I have another table of their cars and their prices.

id | belongsToUser | carPrice
1    4               5000
2    4               6000
3    4               8000

Now what I need to do is something like this (feel free to rewrite):

   SELECT
      `userName`,
      `carPrice`
   FROM `users`
   LEFT JOIN `cars`
   ON cars.belongsToUser=users.id
   WHERE `id`='4'

Which returns:

Mike | 5000

But I need the most expensive car of a certain user, not the first entry found.

So question: How do I set the LEFT JOIN table to be ordered by carPrice, DESC ?

  • 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-05-20T16:36:06+00:00Added an answer on May 20, 2026 at 4:36 pm

    Try using MAX with a GROUP BY.

    SELECT u.userName, MAX(c.carPrice)
    FROM users u
        LEFT JOIN cars c ON u.id = c.belongsToUser
    WHERE u.id = 4;
    GROUP BY u.userName;
    

    Further information on GROUP BY

    The group by clause is used to split the selected records into groups based on unique combinations of the group by columns. This then allows us to use aggregate functions (eg. MAX, MIN, SUM, AVG, …) that will be applied to each group of records in turn. The database will return a single result record for each grouping.

    For example, if we have a set of records representing temperatures over time and location in a table like this:

    Location   Time    Temperature
    --------   ----    -----------
    London     12:00          10.0
    Bristol    12:00          12.0
    Glasgow    12:00           5.0
    London     13:00          14.0
    Bristol    13:00          13.0
    Glasgow    13:00           7.0
    ...
    

    Then if we want to find the maximum temperature by location, then we need to split the temperature records into groupings, where each record in a particular group has the same location. We then want to find the maximum temperature of each group. The query to do this would be as follows:

    SELECT Location, MAX(Temperature)
    FROM Temperatures
    GROUP BY Location;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried googling this, couldn't find an answer, searched here, couldn't find an answer.
I tried googling the answer, but all I found was tips on how to
tried to find the answer by googling and in MSDN but with no luck.
I tried googling this and I haven't found an answer yet to my problem.
I've tried googling for a solution to this problem but haven't yet found one.
This may be a very simple problem, but I couldn't find an answer googleing
I have tried googling it but didn't got the exact answer as required. I
Does anyone know what is := for? I tried googling but it seems google
Pretty much what it says on the tin. I've tried googling around but can't
I'm wondering, is there a known font safe alphabet? I tried googling this 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.