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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:56:02+00:00 2026-05-25T23:56:02+00:00

I have a person table which holds person and his manager at the same

  • 0

I have a person table which holds person and his manager at the same time.
I’m using SELF JOIN to select managers email but I get a lot of duplicates.

http://imageshack.us/photo/my-images/3/withoutgroupby.png

How can I use GROUP BY with my query

SELECT              P.prs_id AS 'Employee_id', M.prs_id AS 'Manager_id', M.prs_email AS 'Manager_email'
FROM                qrd_prs_person AS P
LEFT OUTER JOIN     qrd_prs_person AS M  
ON                  P.prs_manager_number = M.prs_number

GROUP BY M.prs_id

If I add this line at the end of my query to group by Manager_id, I receive this error

Column ‘qrd_prs_person.prs_id’ is invalid in the select list because
it is not contained in either an aggregate function or the GROUP BY
clause.

  • 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-25T23:56:03+00:00Added an answer on May 25, 2026 at 11:56 pm

    I’m not quite sure what you’re trying to achieve?

    If you’re after a query that returns one row per employee, with two optional columns containing the manager’s info, then your original query is correct (without the group by). The relationship is many-to-one, you’re starting with a row per “many” that each has a single (optional) “one”, so there is no need to group by.

    This however is assuming that your data is correct and that prs_number is in fact unique for each employee. If you have two or more managers sharing a prs_number, you will end up with people having multiple managers.

    By making this an outer join you’re also returning people without a manager (i.e. top of the food chain :)), was this your intention?

    EDIT

    If you want only managers returned, then you can’t keep the first column (P.prs_id) and get one row per manager. If you want the list of people that manage one or more people, this will do the trick:

    SELECT              M.prs_id AS 'Manager_id', M.prs_email AS 'Manager_email'
    FROM                qrd_prs_person AS P
    INNER JOIN          qrd_prs_person AS M  
    ON                  P.prs_manager_number = M.prs_number
    GROUP BY            M.prs_id, M.prs_email
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have a table which holds information about person. Columns like NAME or
I have a table Person which contains 2 fields.In my another database i have
Suppose I have table Person table Employee, which inherits Person. I want to get
I have a table called Person which I have already mapped in hibernate I
I have table with date/time column and person column. Each person has multiple records
I have a table that has a column which holds the id of a
I have this person table as super parent, id firstname lastname email telephone ...
I have the following table which allows a person to enter data. What I'm
I totally want to avoid using inline javascript! But i have a table which
I have the following table which holds data on customers and staff. Would it

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.