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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:32:20+00:00 2026-05-23T16:32:20+00:00

let’s say my table schema is like bellow (it’s only a simplified example): MyTable

  • 0

let’s say my table schema is like bellow (it’s only a simplified example):

MyTable (table name)
ID - int (unique, auto increment)
Message - string
Timestamp - Datetime

I want to select the number of ID, group them by message and order them by timestamp, so I’ll do something like this:

SELECT count (ID), Message FROM MyTable
GROUP BY (Message)
ORDER BY Timestamp desc

However, SQL Server management studio throws me this error:

Column 'Timestamp ' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

The problem is that if I put Timestamp in the Group By statement with Message, it messes up my grouping. The other suggestion to put Timestamp in an aggregate function doesn’t make sense (ordering by say, count(Timestamp) doesn’t mean anything…)

Any idea on how to do this?

Thanks a lot!

  • 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-23T16:32:21+00:00Added an answer on May 23, 2026 at 4:32 pm

    Let’s say the same message is in your table multiple times:

           1|the mackerel likes frying|1/1/1917
           2|at night all cats are grey|12/15/1956
           3|the mackerel likes frying|2/2/1918
    

    And you want to group by the message-string, counting the number of times the message appears in the table:

          the mackerel likes frying|2
          at night all cats are grey|1
    

    The timestamp column is NOT part of the aggregation aka the grouping, but is part of the detail row. It CANNOT appear in the grouping, because timestamp is not “it” (singular) but timestamps, they, plural. There are two different timestamps in the example above for the mackerel message. Which one would you choose? How would the query know which one it was? All you have at your disposal are the aggregate functions:

            min(timestamp)
            max(timestamp)
            count(timestamp)
    

    and if it were other than a datetime, you’d also have AVG(timestamp).

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

Sidebar

Related Questions

Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have table with column 'URL' whrere I store urls like this
Let's say that I have classes like this: public class Parent { public int
Let's say I have a simple Login servlet that checks the passed name and
Let's say I have some content classes like Page, TabGroup, Tab, etc. Certain of
Let's say I need a 3-digit number, so it would be something like: >>>
Let's say I can call a method like this: core::get() . What is the
Let's say I have window.open (without name parameter), scattered in my project and I
Let's say I have a text file composed like this ##### typeofthread1 ##### typeofthread2
Let's say there is a graph and some set of functions like: create-node ::

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.