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

  • Home
  • SEARCH
  • 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 163689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:36:40+00:00 2026-05-11T11:36:40+00:00

I have the following table: CREATE TABLE `score` ( `score_id` int(10) unsigned NOT NULL

  • 0

I have the following table:

CREATE TABLE `score` (       `score_id` int(10) unsigned NOT NULL auto_increment,       `user_id` int(10) unsigned NOT NULL,       `game_id` int(10) unsigned NOT NULL,       `thescore` bigint(20) unsigned NOT NULL,       `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,       PRIMARY KEY  (`score_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;   

That’s a score table the stores the user_id and game_id and score of each game. there are trophies for the first 3 places of each game. I have a user_id and I would like to check if that specific user got any trophies from any of the games.

Can I somehow create this query without creating a temporary table ?

  • 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. 2026-05-11T11:36:41+00:00Added an answer on May 11, 2026 at 11:36 am
    SELECT s1.* FROM score s1 LEFT OUTER JOIN score s2   ON (s1.game_id = s2.game_id AND s1.thescore < s2.thescore) GROUP BY s1.score_id HAVING COUNT(*) < 3; 

    This query returns the rows for all winning games. Although ties are included; if the scores are 10,16,16,16,18 then there are four winners: 16,16,16,18. I’m not sure how you handle that. You need some way to resolve ties in the join condition.

    For example, if ties are resolved by the earlier game winning, then you could modify the query this way:

    SELECT s1.* FROM score s1 LEFT OUTER JOIN score s2   ON (s1.game_id = s2.game_id AND (s1.thescore < s2.thescore      OR s1.thescore = s2.thescore AND s1.score_id < s2.score_id)) GROUP BY s1.score_id HAVING COUNT(*) < 3; 

    You could also use the timestamp column to resolve ties, if you can depend on it being UNIQUE.

    However, MySQL tends to create a temporary table for this kind of query anyway. Here’s the output of EXPLAIN for this query:

    +----+-------------+-------+------+---------------+------+---------+------+------+---------------------------------+ | id | select_type | table | type | possible_keys | key  | key_len | ref  | rows | Extra                           | +----+-------------+-------+------+---------------+------+---------+------+------+---------------------------------+ |  1 | SIMPLE      | s1    | ALL  | NULL          | NULL | NULL    | NULL |    9 | Using temporary; Using filesort |  |  1 | SIMPLE      | s2    | ALL  | PRIMARY       | NULL | NULL    | NULL |    9 |                                 |  +----+-------------+-------+------+---------------+------+---------+------+------+---------------------------------+ 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 106k
  • Answers 106k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The ViewInjectionComposition QuickStart has a great example of what you… May 11, 2026 at 8:58 pm
  • Editorial Team
    Editorial Team added an answer I found a way to do this - first you… May 11, 2026 at 8:58 pm
  • Editorial Team
    Editorial Team added an answer = compares numbers. eq? tests if the parameters represent the… May 11, 2026 at 8:58 pm

Related Questions

I have the following table: CREATE TABLE [dbo].[EntityAttributeRelship]( [IdNmb] [int] IDENTITY(1,1) NOT NULL, [EntityIdNmb]
Say I have the following table: Create Table Comments ( ID Int Identity(1,1) Not
For example, I have the following table: CREATE TABLE `test` ( `total_results` int(10) unsigned
In MICROSOFT SQL SERVER have the following table: CREATE TABLE [T1] ( [ID] int

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.