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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:48:29+00:00 2026-05-26T12:48:29+00:00

Running the following query SET @rownum := 0; SELECT customer_id, @rownum := @rownum +1

  • 0

Running the following query

SET @rownum := 0;    
SELECT customer_id, @rownum := @rownum +1 AS rank, score
FROM game_table_customers gtc
INNER JOIN customers c ON c.customers_id = gtc.customer_id
INNER JOIN game_table gt ON gtc.table_id = gt.table_id
WHERE c.my_team =11095
AND gt.event_id =21110
ORDER BY score DESC
LIMIT 0 , 30

The correct result should look like this

CustID  Rank    Score
2        1     130000
39       2     99426
84       3     99178
259      4     98963
339      5     97796

However, what I am getting is the following

CustID  Rank    Score
2        2      130000
39      11      99426
84      20      99178
259     54      98963
339     69  97796

When I exclude the event_id clause I get the correct result. However when the event_id is included it skews it. I have tried only the event_id (removing the my_team clause) and same incorrect result.

Any ideas/suggestions as to why the result may be off would be much appreciated

  • 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-26T12:48:30+00:00Added an answer on May 26, 2026 at 12:48 pm

    I guess this has to do with the execution plan selected in every case and the mix with applying of row numbers – in some of those plans. The row numbers are calculated and then the WHERE conditions are evaluated, so you see non-consecutive row numbers.

    Try this (first getting the 30 results you need, then applying row numbers):

    SET @rownum := 0; 
    SELECT customer_id, @rownum := @rownum +1 AS rank, score
    FROM
      ( SELECT customer_id, score
        FROM game_table_customers gtc
          INNER JOIN customers c ON c.customers_id = gtc.customer_id
          INNER JOIN game_table gt ON gtc.table_id = gt.table_id
        WHERE c.my_team =11095
          AND gt.event_id =21110
        ORDER BY score DESC
        LIMIT 0 , 30
      ) tmp
    ORDER BY score DESC
    

    I can’t test it now but you can also try this:

    SELECT customer_id, @rownum := @rownum +1 AS rank, score
    FROM game_table_customers gtc
      INNER JOIN customers c ON c.customers_id = gtc.customer_id
      INNER JOIN game_table gt ON gtc.table_id = gt.table_id
      CROSS JOIN (SELECT @rownum := 0 AS rn) dummy  
    WHERE c.my_team =11095
      AND gt.event_id =21110
    ORDER BY score DESC
    LIMIT 0 , 30
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running following query.. Select T1.* from T1 LEFT JOIN T2 ON T1.C1
I am running following query. SELECT T1.C1, T2.C2..., IF( T1.C1<>T2.C1,Changed,1) AS NewColumn From T1
I'm currently running the following query: SELECT * from people WHERE id = 4;
Using phpMyAdmin and running the following query I get 19 registers: SELECT * FROM
When running the following the query. select * from surgicals where to_char(dt_surgery ,'DD-MM-YYYY' )
I tried running the following query to restore a database: restore database myDatabase from
I'm running the following query SELECT ROW_NUMBER() OVER(ORDER BY [TransactionValues].[ID]) AS idx, [Transactions].[ID] AS
I have the following query running on a classic asp page. sSQL = Select
I am running following query to find the best winning streak for user. $sql=select
I'm running the following UPDATE query and having no succes: $sql=UPDATE users SET firstname='.$_GET['fn'].',lastname='.$_GET['ln'].',email='.$_GET['emadd'].'

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.