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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:56:56+00:00 2026-06-08T08:56:56+00:00

Totally 12 db tables(some tables repeated). I have to fetch SUM(values) from each table

  • 0

Totally 12 db tables(some tables repeated). I have to fetch SUM(values) from each table of particular date.I have used UNION query,But it returns the value of first table used in query.
Remaining table returned nothing.Can Anybody help me.Here my code.

$sel = mysql_query("
SELECT 
    SUM(collection_amount) AS cash_total 
FROM 
    collection_entry 
WHERE 
    date='$entered_date' 
    AND collection_type='DC' 
UNION 
SELECT 
    SUM(amt) AS cheque_redeposit_total 
FROM 
    cheque_redeposit 
WHERE 
    redeposited_on1 
    OR redeposited_on2='$entered_date' 
UNION 
SELECT 
    SUM(collection_amount) AS not_cleared_total 
FROM 
    collection_entry 
WHERE 
    cheque_status='not cleared' 
    AND date='$entered_date' 
UNION 
SELECT 
    SUM(collection_amt) AS route_collection_total 
FROM 
    route_collection 
WHERE 
    entered_date='$entered_date' 
UNION 
SELECT 
    SUM(amt) AS return_total 
FROM 
    cheque_return 
WHERE 
    return_date1 OR return_date2 OR return_date3='$entered_date' 
UNION 
SELECT 
    SUM(collection_amount) AS cheque_total 
FROM 
    collection_entry 
WHERE 
    collection_type='CC' 
    AND date='$entered_date' 
UNION 
SELECT 
    SUM(debit2) AS voucher_receipt_total 
FROM 
    voucher_posting 
WHERE 
    receipt_type='R' 
    AND date='$entered_date' 
UNION 
SELECT 
    SUM(credit2) AS voucher_payment_total 
FROM 
    voucher_posting 
WHERE 
    receipt_type='P' 
    AND date='$entered_date' 
UNION 
SELECT 
    SUM(amt) AS others_total 
FROM 
    others_remittance 
WHERE 
    entered_date='$entered_date' 
UNION 
SELECT 
    SUM(amt) AS short_total 
FROM 
    short_remittance 
WHERE 
    entered_date='$entered_date' 
UNION 
SELECT 
    SUM(amount) AS more_paid 
FROM 
    difference 
WHERE 
    entered_date='$entered_date' 
    and paid_type='more' 
UNION 
SELECT 
    SUM(amount) AS unpaid 
FROM 
    difference 
WHERE 
    entered_date='$entered_date' 
    and paid_type='unpaid'");
 while($row=mysql_fetch_array($sel)) 
 {
  $cash_total=$row['cash_total'];
  $cheque_redeposit_total=$row['cheque_redeposit_total'];
  $not_cleared_total=$row['not_cleared_total'];
  $route_collection_total=$row['route_collection_total'];
  $return_total=$row['return_total'];
  $cheque_total=$row['cheque_total'];
  $voucher_receipt_total=$row['voucher_receipt_total'];
  $voucher_payment_total=$row['voucher_payment_total'];
  $others_total=$row['others_total'];
  $short_total=$row['short_total'];
  $more_paid=$row['more_paid'];
  $unpaid=$row['unpaid'];
  $net_total = (($cash_total + $route_collection_total) - $return_total);
 }
  • 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-08T08:57:02+00:00Added an answer on June 8, 2026 at 8:57 am

    UNION just appends rows to one another. So in your case you just get a list of your sums in a row-wise fashion.

    • [value for cash_total]
    • [value for cheque_redeposit_total]
    • [value for not_cleared_total]
    • …

    If you really have to get all the data in one row, you can use something like this:

    SELECT * FROM
    (SELECT SUM(collection_amount) AS cash_total FROM collection_entry WHERE date='$entered_date' AND collection_type='DC') as t1,
    (SELECT SUM(amt) AS cheque_redeposit_total FROM cheque_redeposit WHERE redeposited_on1 OR redeposited_on2='$entered_date') AS t2,
    (SELECT SUM(collection_amount) AS not_cleared_total FROM collection_entry WHERE cheque_status='not cleared' AND date='$entered_date') AS t3,
    (SELECT SUM(collection_amt) AS route_collection_total FROM route_collection WHERE entered_date='$entered_date') AS t4,
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm totally confused on this matter, some say use tables and others say it's
I feel totally stupid. I'm rusty with my sql. I have two tables, Message
Okay to keep it short: I have some different websites with tables containing information
I have a table with name,age and address.I have totally five rows of data
Brain totally not working today. So, I have a few columns in a table
I need to check if a database is totally empty (no tables) using an
Creating liquid layouts is an immense pain. Now, I totally understand that tables should
Totally new to programming so kindly excuse the silly question. I have this URL
Totally new to Capistrano. I have a local git repository that I want to
Totally confused here. I have a PARENT UIViewController that needs to pass an NSMutableArray

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.