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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:25:56+00:00 2026-06-10T07:25:56+00:00

I’m working with stock price data and making this query to get one price

  • 0

I’m working with stock price data and making this query to get one price per month for, say, Google (from a table with prices for every weekday):

SELECT * FROM pricedata WHERE symbol='GOOG' GROUP BY symbol,month(date),year(date)

2012-07-02
2012-06-01
2012-05-01

If I remove the WHERE clause it returns the last date of the month instead of the first (and more rows because all the symbols in the table show up, of course), as in

SELECT * FROM pricedata GROUP BY symbol,month(date),year(date)

2012-07-31
2012-06-29
2012-05-31

I understand that ‘The server is free to choose any value from each group’, so I’m probably just lucky that the first query works as I want, but I’d like to know why the change occurs.

Is there a fast solution to consistently get the first value of each month? I haven’t found any similar questions, but they might be out there… The second query isn’t vital but I was trying to build a reduced-size table for monthly-only records and ran into this problem.

  • 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-06-10T07:25:58+00:00Added an answer on June 10, 2026 at 7:25 am

    I’d like to know why the change occurs.

    The server is free to choose any value from the group, but in practice it chooses the first it finds. If you have an index on symbol then it will choose the first one as they are sorted in the index. If you remove the WHERE clause it will use another index or the clustered key. This will be sorted in a different order, and therefore the first row the server encounters will be different.

    Basically you should not ever rely on getting any specific value. As the documentation says, the server is free to choose any value and which value it chooses is not specified.

    Is there a fast solution to consistently get the first value of each month?

    SELECT symbol, MIN(date) AS date
    FROM pricedata
    GROUP BY symbol, month(date), year(date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.