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 165819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:59:21+00:00 2026-05-11T11:59:21+00:00

When using the SQL MIN() function, along with GROUP BY, will any additional columns

  • 0

When using the SQL MIN() function, along with GROUP BY, will any additional columns (not the MIN column, or one of the GROUP BY columns) match the data in the matching MIN row?

For example, given a table with department names, employee names, and salary:

SELECT MIN(e.salary), e.* FROM employee e GROUP BY department 

Obviously I’ll get two good columns, the minimum salary and the department. Will the employee name (and any other employee fields) be from the same row? Namely the row with the MIN(salary)?

I know there could very possibly be two employees with the same (and lowest) salary, but all I’m concerned with (now) is getting all the information on the (or a single) cheapest employee.

Would this select the cheapest salesman?

SELECT min(salary), e.* FROM employee e WHERE department = 'sales' 

Essentially, can I be sure that the data returned along with the MIN() function will matches the (or a single) record with that minimum value?

If the database matters, I’m working with MySql.

  • 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. 2026-05-11T11:59:21+00:00Added an answer on May 11, 2026 at 11:59 am

    If you wanted to get the ‘cheapest’ employee in each department you would have two choices off the top of my head:

    SELECT      E.*     -- Don't actually use *, list out all of your columns FROM      Employees E INNER JOIN      (           SELECT                department,                MIN(salary) AS min_salary           FROM                Employees           GROUP BY                department      ) AS SQ ON      SQ.department = E.department AND      SQ.min_salary = E.salary 

    Or you can use:

    SELECT      E.* FROM      Employees E1 LEFT OUTER JOIN Employees E2 ON      E2.department = E1.department AND      E2.salary < E1.salary WHERE      E2.employee_id IS NULL -- You can use any NOT NULL column here 

    The second statement works by effectively saying, show me all employees where you can’t find another employee in the same department with a lower salary.

    In both cases, if two or more employees have equal salaries that are the minimum you will get them both (all).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 132k
  • Answers 132k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Well there is a TextChanged event in the TextBox that… May 12, 2026 at 6:30 am
  • Editorial Team
    Editorial Team added an answer Always quote strings. To check if the string $date_alarm contains… May 12, 2026 at 6:30 am
  • Editorial Team
    Editorial Team added an answer It smells like something with your schema is not ok… May 12, 2026 at 6:30 am

Related Questions

I have a table with some 30 columns, already used in the application extensively.
What tools are you using to track changes in your MySQL database? Currently I'm
We have a Delphi 7 application that runs as an ISAPI extension in IIS6.
I would like to provide a WHERE condition on an inner query by specifying

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.