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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:28:56+00:00 2026-05-26T04:28:56+00:00

SELECT r.game, u.username, r.userid, r.points, u.format FROM .TBL_RANKING. r INNER JOIN .TBL_USERS. u ON

  • 0
SELECT r.game, u.username, r.userid, r.points, u.format  
FROM ".TBL_RANKING." r 
    INNER JOIN ".TBL_USERS." u 
    ON u.id = r.userid
WHERE r.type = '1' AND r.game = 
            (SELECT name 
             FROM ".TBL_GAME." 
             WHERE active = '1' 
             ORDER BY rand() 
             LIMIT 1) 
     AND u.format = 
           (SELECT name 
            FROM ".TBL_FORMAT." 
        WHERE active = '1' 
            ORDER BY rand() LIMIT 1)
ORDER BY r.points DESC LIMIT 5

This query isn’t working as it’s supposed to. It’s selecting the odd user and sometimes none at all.

The query should:
-select a random game from the game table
-select a random format from the format table
-select users ranked on that game but only from the format selected

so if the random selection was FIFA 12 Xbox 360, it would find all users that are from format type Xbox 360 and are ranked on FIFA 12.

The table structure is as follows:

*tbl_ranking*
 id 
 userid 
 game 
 points 
 type

*tbl_users*
id
username
format

*tbl_game*
id
name

*tbl_format*
id 
name

Can anyone see a problem here?

  • 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-26T04:28:57+00:00Added an answer on May 26, 2026 at 4:28 am

    try to have sub queries using left join

    SELECT r.game, u.username, r.userid, r.points, u.format 
      FROM TBL_RANKING r 
     INNER JOIN TBL_USERS u 
        ON u.id = r.userid 
      LEFT JOIN (SELECT name FROM ".TBL_GAME." WHERE active = '1' ORDER BY rand() LIMIT 1)  temp1
        ON r.game=temp1.name
      LEFT JOIN (SELECT name FROM ".TBL_FORMAT." WHERE active = '1' ORDER BY rand() LIMIT 1)  temp2
        ON u.format=temp2.name
     WHERE r.type = '1' 
       AND temp1.name != ''
       AND temp2.name != ''
     ORDER BY r.points DESC LIMIT 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SELECT game_ratingstblx245v.game_id,avg( game_ratingstblx245v.rating ) as avg_rating, count(DISTINCT game_ratingstblx245v.userid) as count, game_data.name, game_data.id , avg(game_ratings.critic_rating),count(DISTINCT
I have a list of Games users can join. To select a game ,
I have this sql statement: SELECT game.game_id FROM game, userGame WHERE userGame.user_id = 1
SELECT DISTINCT _id, Game_name, Book, Chapter, Verse_start, Verse_stop, Scripture FROM Bible_Game WHERE God's Kingdom
SELECT events.title FROM events ORDER BY events.title DESC I'm getting the proper ordering for
select @result=@input.query('*') for xml raw,type Above statement will generate following alert: Msg 6819, Level
SELECT sum(TotalHoursM) + (TotalHoursT) + (TotalHoursW) + (TotalHoursTH) + (TotalHoursF) AS TOTAL FROM LeaveRequest
SELECT (SELECT IIF(IsNull(sum(b.AmountCharged) - sum(b.AmountPaid)), a.Balance, (sum(b.AmountCharged) - sum(b.AmountPaid))) FROM tblCurrentTransaction AS b WHERE
SELECT AVG(variable) AS Expr1, SUM(variable) AS Expr2 FROM ...... result for AVG is 2,
SELECT * FROM menu WHERE item_id = 1 OR item_id = 2 OR item_id

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.