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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:33:18+00:00 2026-05-31T05:33:18+00:00

I am a beginner of SQL, having this table instructor: ID name dept_name salary

  • 0

I am a beginner of SQL, having this table instructor:

ID     name   dept_name   salary
001     A       d01        1000
002     B       d02        2000
003     C       d01        3000
...

I am writing a code to find people who have highest salary in each department like:

name      dept_name
 C           d01
 B           d02

I do know how to find maximum value
but I have no idea how to use it by according dept_name for all each department.

  • 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-31T05:33:18+00:00Added an answer on May 31, 2026 at 5:33 am

    This will ensure that only records which are the highest salary for each department are returned to the result set.

    SELECT name, dept_name, salary
    FROM tbl t
    WHERE NOT EXISTS(SELECT salary FROM tbl t2 WHERE t2.salary>t.salary AND t2.dept_name=t.dept_name)
    

    Using SELECT name, MAX(salary) like other answerers have used won’t work. Using MAX() will return the highest salary for each department, but the name will not necessarily be related to that salary value.

    For example, SELECT MIN(salary), MAX(salary) is most likely going to pull values from different records. That’s how aggregate functions work.

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

Sidebar

Related Questions

This is a beginner question, I have to create some SQL Reports with business
I'm a beginner in sql and I am doing this through a php document.
Please help this beginner here... I have a SQL Server 2008 R2 running on
I am a beginner SQL user (not formally trained; OJT only) and need some
I'm a beginner with SQL and am working on one of my first databases.
SQL Server Beginner question: I'm trying to introduce a computed column in SQL Server
Absolute beginner question: I have a template file index.html that looks like this: ...
I am a beginner to SQL, so bear with me. I'm trying to create
I am a beginner in SQL Functions. What is the best way to create
i am beginner with sql, I have comments Template with button in the end

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.