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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:22:46+00:00 2026-05-22T20:22:46+00:00

I tried to run the following query: select a,b,min(c) from tablename where e=1 and

  • 0

I tried to run the following query:

select a,b,min(c) from tablename where e=1 and f=1 group by a,b order by a,b,c

But got the error:

Column name 'tablename.c' is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.

However c is contained in the aggregate function min(), so what’s the issue here? Is there a workaround?

This is on sqlserver 2000 (using the sqlserver 2008 management console).

  • 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-22T20:22:47+00:00Added an answer on May 22, 2026 at 8:22 pm

    As you are using the aggregation on that column, is no longer c but “aggregated c” that is why you can not use it in the order by clause.

    You need to alias that column to use it in order by

    select a,b,min(c) as min_c from tablename where e=1 and f=1 group by a,b order by a,b,min_c
    

    EDIT:

    Why the column c is not available ?

    While in the statement we use clause group by, our original table i transformed into new temporary one.

    In your case you used the column a and b to group, the the data in those column will not be changed only limited to unique.

    On the column c you are using a function that for each unique group will retrieve the lowest value of c, for this purpose a new column has to be created that will store that results.

    The order by clause is the last part of query that is executed over the select section. So over the result of the temporary table not the source one.

    The simply order of statement execution goes like this:

    FORM 
     JOIN
    WHERE
    GROUP BY 
    HAVING 
    SELECT 
    ORDER BY 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following query: SELECT wm_concat(DISTINCT NAME) as Methods FROM TPM_TRAININGPLAN JOIN TPM_DELIVERYMETHODS
I run the following query SELECT * FROM ( SELECT * FROM Client );
I run the following query on my database : SELECT e.id_dernier_fichier FROM Enfants e
I'm using the YQL console to run the following query: select * from xml
I received the following error when I tried to run a C# WinForms application
I am using the following query to return a single value: select er.elig_code from
I have the following hive query: select count(distinct id) as total from mytable; which
I've got the following WIQL query for a TFS project: string query = SELECT
I'm trying to run the following query in SQLite 3: SELECT *, DISTANCE(latitude, longitude,
Following query runs well in MySQL 5.x SELECT m_area.id, m_area.cn_areaName, m_area.de_areaName, m_area.en_areaName,m_area.jp_areaName,t_shop.count FROM m_area

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.