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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:45:54+00:00 2026-05-27T21:45:54+00:00

SELECT Id, Value, Sender, Recipient, MIN(DateTime), TypeOf, VideoId, Likes, Comments FROM xx.dbo.StreamView WHERE StreamView.TypeOf

  • 0
SELECT Id, Value, Sender, Recipient, MIN(DateTime), TypeOf, VideoId, Likes, Comments
FROM xx.dbo.StreamView
WHERE StreamView.TypeOf = 3 AND StreamView.[DateTime] >= "Some DateTime Value Here"

I am trying to get the latest record directly newer than the given DateTime value.

when executing this query I am receiving the following error:

Msg 207, Level 16, State 1, Line 1
Invalid column name 'Some DateTime Value Here'.

Also, when removing this line AND StreamView.[DateTime] >= "Some DateTime Value Here"

I am getting:

Msg 8120, Level 16, State 1, Line 1
Column ‘xx.dbo.StreamView.Id’ is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Suggestions? Thanks.

Update

WITH
  sequenced_records AS
(
  SELECT
    ROW_NUMBER() OVER (ORDER BY [DateTime] DESC) AS sequence_id,
    *
  FROM
    xx.dbo.StreamView
  WHERE
    StreamView.TypeOf = 3
    AND StreamView.[DateTime] >= "2011-12-29 01:38:21.607"
)
SELECT
  *
FROM
  sequenced_records
WHERE
  sequence_id = 1

returns -> Msg 207, Level 16, State 1, Line 11
Invalid column name ‘2011-12-29 01:38:21.607’.

Update 2

guys I need to return just a SINGLE record with the minimum datetime in a group of selected items bigger than the given datetime.

  • 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-27T21:45:54+00:00Added an answer on May 27, 2026 at 9:45 pm

    MIN() is an aggregate, and as the error says; you must use GROUP BY to use aggregate queries. This means that you can’t get the MIN() of a group and have the individual values from one record in the group at the same time.

    There are two alternatives…
    – Use GROUP BY to get the MIN() and then use that to look up the record it matches.
    – Use an alternative approach, such as ROW_NUMBER()

    WITH
      sequenced_records AS
    (
      SELECT
        ROW_NUMBER() OVER (ORDER BY [DateTime] ASC) AS sequence_id,
        *
      FROM
        xx.dbo.StreamView
      WHERE
        StreamView.TypeOf = 3
        AND StreamView.[DateTime] >= "Some DateTime Value Here"
    )
    SELECT
      *
    FROM
      sequenced_records
    WHERE
      sequence_id = 1
    

    NOTE You do need real datetime in there, such as ‘01012012 23:34’

    For environments without ROW_NUMBER() you’d revert to the aggregate approach, using two steps. Such as…

    SELECT
      *
    FROM
      StreamView
    WHEREE
      TypeOf = 3
      AND DateTime = (SELECT MIN(DateTime) FROM StreamView WHERE TypeOf = 3 AND DateTime >= '01012012 23:34')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select value from select list in RSpec . For example i
This works: from x in table.AsEnumerable() where x.Field<string>(something) == value select x.Field<decimal>(decimalfield); but, this
Using Django 1.1, I am trying to select the maximum value from a varchar
With Perl's WWW::Mechanize module, I want to select a random value from a select
Using C# & MySQL When i select a particular value from the combobox then
SELECT * FROM LiveStreams l INNER JOIN Friendships f ON f.Sender = l.Sender OR
My requirement is to select a value from a drop down and fetch the
I need to pass a string value from Form1 : public void button1_Click(object sender,
I'm trying to select some fields from my database and store them as a
So I've been working with this : SELECT DISTINCT l.* FROM StreamView l JOIN

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.