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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:16:52+00:00 2026-05-25T22:16:52+00:00

I have a table with two columns team and date . The date column

  • 0

I have a table with two columns team and date. The date column has the date that the entry was added to the table.

I want to print the last 10 entries of each team sorted by date DESC.
I also want to sort these groups of team entries by date DESC.

I tried a lot of things, but with no luck. It worked, but with 2 queries which is not acceptable in this case.

How can I do this with a single query? I have the feeling that this is a really newbie question.

  • 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-25T22:16:53+00:00Added an answer on May 25, 2026 at 10:16 pm
    SELECT rows.team, rows.date FROM (
      SELECT team, date,
        IF( @prev <> team, @rownum := 1, @rownum := @rownum+1 ) AS rownum,
        @prev := team
      FROM my_table
      JOIN (SELECT @rownum := NULL, @prev := 0) AS init
      ORDER BY team, date DESC
    ) AS rows
    WHERE rownum <= 10
    

    We make a temporary (virtual) table in the sub-query with rows ordered by team, date DESC and we start from the top giving an incrementing row number to each row and whenever team changes we reset the row number, then in the outer query we filter out any row that has row number greater than 10.

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

Sidebar

Related Questions

I have a table containing two columns in SQL that I want to extract
I have a table with two columns, date and score. I want to find
I have table that has two columns and I need to concatenate these two
I have a table with two columns. I want to center the right-most column
I have two tables: players (has a team name column) and teams (also has
Say I have table with two columns: Name, Age. I want to design a
I have one table [table] with two columns that needs to be filtered: [column1]
I have a table with two columns that might be null (as well as
I have a table with two columns: City Country I want a result set
Let's say I have a table with two columns, one column for the ID

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.