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 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

Related Questions

I have the following table structure CREATE TABLE `table` ( `id` int(11) NOT NULL
Suppose I have the following tables: CREATE TABLE Game ( GameID INT UNSIGNED NOT
I have the following table schema; CREATE TABLE `db1`.`sms_queue` ( `Id` INTEGER UNSIGNED NOT
I have the following table in MySQL (version 5): id int(10) UNSIGNED No auto_increment
For example, I have the following table: CREATE TABLE `test` ( `total_results` int(10) unsigned
I have the following table and data in SQL Server 2005: create table LogEntries
I have the following database table created thus: CREATE TABLE AUCTIONS ( ARTICLE_NO VARCHAR(20),
I have the following rails migration: create_table :articles do |t| t.integer :user_id, :allow_null =>
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following table relationship in my database: Parent / \ Child1 Child2

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.