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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:47:53+00:00 2026-05-15T23:47:53+00:00

I am trying to retrieve two counts from two separate tables into one SQL

  • 0

I am trying to retrieve two counts from two separate tables into one SQL query to use with PHP. This is the current SQl query:

SELECT COUNT(entryid) AS total FROM rh_entries UNION SELECT COUNT(pentryid) AS attended FROM rh_playerentries WHERE playerid=79

This is the PHP I am using to utilize the data:
$result = mysql_query($query);

$attendance = mysql_fetch_assoc($result);
echo "Total: " . $attendance['total'] 
 . " Attended: " . $attendance['attended'] 
 . " Percentage: " 
 . (int)$attendance['total'] / (int)$attendance['attended'] 
 . " <br />";

I am getting this output:

Warning: Division by zero in /home/content/g/V/i/gViscardi/html/guilds/sanctum/raidinfo/player.php on line 41
Total: 6 Attended: Percentage: 

Apparently the $attendance[‘attended’] is not being set properly. Am I missing something on how UNION or COUNT or AS works?

  • 1 1 Answer
  • 2 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-15T23:47:54+00:00Added an answer on May 15, 2026 at 11:47 pm

    Union combines the contents of two queries into a single table. Your queries have different column names, so the merge won’t work properly. You’ll want something like:

    SELECT 
        (SELECT COUNT(entryid) FROM rh_entries) as total, 
        (SELECT COUNT(pentryid) FROM rh_playerentries WHERE playerid=79) as attended;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to do an SQL query on two tables to retrieve multiple
I'm trying to retrieve data from two tables, 'publisher' and 'magazine'. I'm listing the
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
Hi I am trying to use the list() function to retrieve two variables from
I'm trying to retrieve a boolean value from one of two member functions. I
I'm trying to retrieve multiple rows from joining two tables where store.itemid = item_list.id.
I was trying to retrieve value from two tables by joining, but few values
I am trying to write a SQL query where I am joining two tables
Using PHP. I'm trying to retrieve $_POST values from a the second dimension of
I'm trying to retrieve two columns from the DB with iBatis. I want to

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.