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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:28:58+00:00 2026-06-18T15:28:58+00:00

I have a order table that stores order meta include their date, sample data

  • 0

I have a order table that stores order meta include their date, sample data like the following

date      |order-id
2010-12-16|106
2010-12-18|112
2009-03-05|115
2009-03-05|122

now I need to create folder that groups all the orders from the same month and pick the first order in the month as showcase, but it appears group by always pick the last row in my query below

SELECT orders.id, order.date from orders
GROUP BY strftime('%Y-%m', orders.date)

it returns the last row of each month

2010-12-18|112
2009-03-05|122

so I’d like it to return

2010-12-16|106   
2009-03-05|115

(106: earlier in the month)
(115: same date as the other one, but this will match the 1st one if I do a sorted order query for the month)

I tried the JOIN query, it works if I don’t have multiple orders on the same day, but in the case of 2009-03, it still returns the last row, instead of the first row…

SELECT o.id, o.date
FROM orders o
JOIN 
   (SELECT MIN(date) as first_date FROM orders 
    GROUP BY strftime('%Y-%m', orders.date)
   ) as sorted_orders
ON o.creation_date=sorted_order.first_date
GROUP BY strftime('%Y-%m', orders.date)

Anything else I can try?

  • 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-18T15:28:59+00:00Added an answer on June 18, 2026 at 3:28 pm

    Your second query does not work because you are not actually selecting any column from the sorted_orders subquery.

    Anyway, if you have SQLite 3.7.11 or later, records in a GROUP BY query are guaranteed to come from the record in a group that matches a MIN or MAX for that group:

    SELECT id, MIN(date)
    FROM orders
    GROUP BY strftime('%Y-%m', date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that stores hierarchical relationships.They stored as strings like 1.1, 1.1.1,
I have a table that stores locations of users. I would like to select
I have a table that stores data on days of the week. I'm wanting
I have a table that stores articles, like the example: Article table: ID #CategoryID
I have a table (in MySQL) that stores votes. The structure is like this:
I have a table that stores the data as follows: ID ListId ModuleId RecordId
I have a table that looks like: Client_ID | Order_ID | 10 | 1
I have the following Mysql Table Order table status 0 - incomplete status 1
I have the following table: Order Product Price Quantity Description Order1 Product1 12 1
I have a table like: I have to order the rows in function of

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.