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

  • Home
  • SEARCH
  • 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 5996503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:06:45+00:00 2026-05-23T00:06:45+00:00

I have a data set that i am attempting to select the first record

  • 0

I have a data set that i am attempting to select the first record with a station id of 2.

InspectionNbr   Station          DateTimeStamp
825065             1            2010-11-16 04:38:49.000
825065             2            2010-11-16 12:38:31.000
825065             2            2010-12-06 01:35:14.000
825065             2            2011-01-24 08:11:04.000

In this case i want to select the second line of the results. How can i use SQL to get the minimum date where stationid = 2?

That being stated, this is what i have.
i created a temporary table in SQL. i have it setup to populate the table with the latest date. Then i attempt and update the temporary table with the following code

UPDATE @report_out 
 set    
DateTimeStamp = Min(si.CreatedDate)
 from
@report_out as r
 INNER JOIN
StationInspection as si
    on si.ModifiedDate = r.DateTimeStamp
where
r.Station = 2

For some reason beyond me it doesn’t like the DateTimeStamp = Min(si.CreatedDate)
i get the follwing error:
An aggregate may not appear in the set list of an UPDATE statement.

any pointers?

  • 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-23T00:06:46+00:00Added an answer on May 23, 2026 at 12:06 am

    As far as I can figure out, an aggregate can’t be used in an update statement because the aggregate and the update affect two different row sets. Think about a normal SELECT with an aggregate:

    SELECT MIN(CreatedDate)
    FROM StationInspection
    WHERE Station = 2
    

    The aggregate works on all rows in the row set. The row set is determined by the WHERE clause, which determines which rows will be in the row set.

    In an update statement, the WHERE clause determines which rows will be changed:

    UPDATE StationInspection
    SET CreatedDate = @newDate
    WHERE Station = 2
    

    The update affects all rows in the row set (all rows that pass the filter specified by the WHERE clause).

    So, in the case where you try to do both (I realize this is somewhat simplified from your code, but it makes the point):

    UPDATE StationInspection
    SET CreatedDate = MIN(CreatedDate)
    WHERE Station = 2
    

    You have two operations that require unique row sets, but only one row set selector (WHERE clause).

    SQL doesn’t support two WHERE clauses in a single statement. So you’ll need two statements:

    DECLARE @newDate datetime
    
    SELECT @newDate = SELECT MIN(CreatedDate)
    FROM StationInspection
    WHERE Station = 2
    
    UPDATE StationInspection
    SET CreatedDate = @newDate
    WHERE Station = 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set that is organized in the following manner: Timestamp|A0001|A0002|A0003|A0004|B0001|B0002|B0003|B0004 ...
We have this set of data that we need to get the average of
I have a set of data that models a hierarchy of categories. A root
I have a set of data that needs to be displayed as a crosstab
I have a costumer showing Notepad with a large set of data that looks
I am working with a set of data that I have converted to a
I have a set of data protected by 16bit checksums that I need to
so i have a winforms apps that downloads a set of data syncronously on
So I have made a webservice that interfaces with a set of data contained
I have a set of core, complicated JavaScript data structures/classes that I'd like to

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.