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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:02:15+00:00 2026-05-26T22:02:15+00:00

I am using a group by clause in my query. I want to get

  • 0

I am using a group by clause in my query. I want to get other columns not specified in the group by parameters

SELECT un.user, un.role 
FROM [Unique] un 
group by user, role

In the query about [Unique] has 7 columns altogether. How do I get the other columns?

  • 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-26T22:02:16+00:00Added an answer on May 26, 2026 at 10:02 pm

    In most databases (MySQL and SQLite are the exceptions I know of), you cannot include a column in a GROUP BY SELECT unless:

    1. The column is included in the GROUP BY clause.

    2. The column is aggregated in one of the supported aggregate functions.

    In MySQL and SQLite, the rows inside the aggregate groups from which the extra values get taken are undefined.

    If you want extra columns in any other engine, you can wrap the column names in MAX():

     SELECT un.user, un.role, MAX(un.city), MAX(un.bday)
     FROM [Unique] un 
     GROUP BY user, role
    

    In this case, the values for the extra columns are likely to come from different rows in the input record set. If this is important (sometimes it isn’t since the extra columns come from the one side of a one-to-many JOIN), you can’t use this technique.

    Just to be clear: If you use GROUP BY in a SELECT, then each row you get back is constructed out of groups of multiple rows in the table you’re SELECTing against. If you include columns that are not part of the GROUP BY clause, you’re not giving the engine any instructions on which row from the table you want that value read from. Most engines, therefore, do not allow you to run this kind of SQL. MySQL does, with undefined results but I personally consider it bad practice to do this.

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

Sidebar

Related Questions

I'm using a linq group by query (with two grouping parameters) and would like
Here is the query I am using: SELECT k_id, COUNT(k_id) AS k_count FROM template_keyword_link
How can I using group by with union in T-SQL? I want to group
I have panel that is using group layout to organize some label. I want
I am using the MySQL GROUP BY function, and want to know if there
I'm using the Filament Group's jQuery Select Slider to produce a form for selecting
I see that in an SQL query, the GROUP BY clause has to precede
This is my base query select distinct a.projects , case when(billing_fy!=0) then(select round(((sum(cost_project)/(sum(billing_fy)/((10/12)*365)))),2) from
I am writing a select query in which I am fetching several columns (by
This query gets the top item in each group using the ranking function. I

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.