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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:49:15+00:00 2026-06-14T02:49:15+00:00

I have a query like this: SELECT PlayerID, COUNT(PlayerID) AS MatchesPlayed, Name, Role, Team,

  • 0

I have a query like this:

SELECT PlayerID, COUNT(PlayerID) AS "MatchesPlayed", Name, Role, Team,
       SUM(Goals) As "TotalGoals", SUM(Autogoals) As "TotalAutogoals",
       SUM(...)-2*SUM(...)+2*SUM(...) AS Score, ...
FROM raw_ordered
GROUP BY PlayerID
ORDER BY Score DESC

where in raw_ordered each row describes the performance of some player in some match, in reverse chronological order.

Since I’m grouping by PlayerID what I get from this query is a table where each row provides the cumulative data about some player. Now, there’s no problem with columns with aggregate functions; my problem is with the Team column.

A player may change team during a season; what I’m interested in here is the last Team he played with, so I’d like to have a way to tell SELECT to take the first value met in each group for the Team column (or, in general, for non-aggregate-function columns).

Unfortunately, I don’t seem to find any (easy) way to do this in SQLite: the documentation of SELECT says:

If the expression is an aggregate expression, it is evaluated across all rows in the group. Otherwise, it is evaluated against a single arbitrarily chosen row from within the group.

with no suggestion about how to alter this behavior, and I can’t find between the aggregate functions anything that just takes the first value it encounters.

Any idea?

  • 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-14T02:49:17+00:00Added an answer on June 14, 2026 at 2:49 am

    SQLite does not have a ‘first’ aggregate function; you would have to implement it yourself.

    However, the documentation is out of date. Since SQLite 3.7.11, if there is a MIN() or MAX(), the record from which that minimum/maximum value comes is guaranteed to be chosen.

    Therefore, just add MAX(MatchDate) to the SELECT column list.

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

Sidebar

Related Questions

I have a query like this: SELECT type.id, type.name, COUNT(*) AS tot FROM page
I have a query like this select Count(1) as Count, pt.Name as TypeName, pt.ID
I have query like this : SELECT EXTRACT(MONTH FROM d.mydate) AS synmonth, SUM(apcp) AS
I have a query like this: select empno,name from emp where job = 'CLERK'
I have a query like this: SELECT COUNT(*) AS amount FROM daily_individual_tracking WHERE sales
I have a query like this SELECT TOWN, NAME FROM CINEMA WHERE CITY_ID =
I have an sql query like this: SELECT IF( (SELECT COUNT(*) FROM `test_table2` WHERE
I have query like this: SELECT *, SUM(ss.rank) as group_sum FROM Standard s, s.SubStandard
I have a query like this: Select E.ID, E.NAME, date_format( CONVERT_TZ( CONVERT_TZ( E.ST, '+00:00',
I have a query like this: SELECT Name, REPLACE(RTRIM(( SELECT CAST(Score AS VARCHAR(MAX)) +

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.