Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

4
Have a column which is the result of another query
Post Body

Hi there.. I couldn't think of any better way to phrase the title, suppose we have these two tables:

CREATE TABLE "Users" (
"Id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"Name" varchar Not NULL);

CREATE TABLE "Scores" (
"Id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"UserId" integer,
"Date" bigint NOT NULL,
"Score" integer,
FOREIGN KEY("UserId") REFERENCES "Users"("Id") ON DELETE CASCADE);

And I want to query for a list of all users with their respective maximum score and the date they got it. Currently I query for the list of users, then for each user I query for all the scores in Scores table where UserId is whatever, ordered by Score descending, then by date, taking only one. It works, although it's a lot of I/O.

Other option would be to check if a score is a personal best whenever there's a new one and update rows "Best score" and "Date of Best" on users table, which would mean denormalizing the table so I'd rather avoiding that approach.

My question is, is there any way to get those rows together in a single query?Thanks in advance..

Ps: I edited the post a hundred times and I just can't get the line breaks right..

Author
Account Strength
90%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
3,466
Link Karma
673
Comment Karma
2,707
Profile updated: 5 days ago
Posts updated: 3 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago