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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:20:24+00:00 2026-06-15T01:20:24+00:00

I got some code that need to look through three tables to display some

  • 0

I got some code that need to look through three tables to display some information for a minecraft top list.
The tables are the following:

servers

id | user_id | name | information | websitename | websiteurl | postdate.. etc

This is the main table that contains server name, website information(Full description of the server) etc.

vote

id | server_id | username | ipaddress | votetimestamp

On the website I allow players to vote every 24 hour. All votes get inserted into this table with the users in-game name(username), the server id and then time of the vote.

ping

id | server_id | min_player | max_player | motd | pingtimestamp

This table get updated by another script every 10 mins with CronJobs that is running on my web server with the use of fsock’s.
Doing this I can find out if the server is offline or online, how many players there is online and how many players that can be online at a time.

On my index page I got a script that should pull out data from all three tables onto the web page and display every server in the database order after the server that got the most votes to the server that got the least votes.

I can pull out every server that already got a vote in the voting table however if there is a server that haven’t received a vote yet it wont get listed which is should.
This is the SQL code I use.

SELECT DISTINCT(ping.server_id), COUNT(vote.server_id) AS count, servers.id,
       servers.name, servers.server_ip, ping.min_player,ping.max_player,ping.motd
  FROM servers,vote,ping
 WHERE servers.id = vote.server_id
   AND servers.id = ping.server_id
 GROUP BY servers.id
 ORDER BY count DESC
 LIMIT $start, $per_page

I’m sure this is simple enough but I’ve tried a few things now but nothing really seem to work.
Would be a good idea to mention at this point that SQL is not really my strong suit.

Edit
I have tried to remove the ´DISTINCT´ in the string but for some reason it returns multiple rows of every server which is displaying the server more then once.
Every server should only be displayed once, sorting from top to bottom after the server that got the most votes to the least.

  • 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-06-15T01:20:26+00:00Added an answer on June 15, 2026 at 1:20 am

    First, don’t use the comma-delimited syntax where you simply list the tables in your From clause; instead use the Join syntax. It would help if you showed us some sample inputs and expected outputs. You stated that you want all servers whether or not they have a vote means you will probably need to use Left Joins:

    Select servers.id
        , Count(vote.server_id) As cnt
        , servers.name
        , servers.server_ip
        , Min(ping.min_player) As min_player
        , Max(ping_ping.max_player) As max_player
        , Min(ping.motd) As Min_Motd
    From servers
        Left Join votes
            On votes.server_id = servers.id
        Left Join ping
            On ping.server_id = servers.id
    Group By servers.id
        , servers.name
        , servers.server_ip
        , ping.server_id
    

    You were not clear on the structure and purpose of the ping table nor the nature of the results if there are multiple rows in the ping table for the same servers.id value. In the above example, I guessed as to the aggregate functions to use for ping.min_player, ping.max_player and ping.motd. In addition, I assumed you really did want all servers rows and not necessarily those that contained a value in the ping table and so I used a Left Join from servers to ping.

    In addition, if servers.id is the primary key of the servers table and since you are using MySQL, you do not need to enumerate all of its columns in the Group By (but you would in other database products). Since it wasn’t stated whether servers.id is the primary key, I enumerated them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)
I've got some code that runs in Enterprise guide (SAS Enterprise build, Windows locally,
I've got some code that lies in a browser, and wrote C++ plugins for
I've got some code that runs all lovely on SQL Server 2008, however I'm
I've got some code that doesn't work the way I expect, and I'd appreciate
I've got some C# code that compiles fine under both mono and the Microsoft's
I've got some code here that works great on IPv4 machines, but on our
I've got some c# code that is mapping processes to ip addresses, I'm basically
I've got some C# code that I'm converting to Objective-C. In C# I would
So I've got some Java code that uses Jakarta HttpClient like this: URI aURI

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.