This is following a previous question a little while back that I am finally able to get to. Here is the link http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/Q_24275987.html . I am working on the User's Home where it will have a summary of what they registered, what they have paid and what they owe. When I try to get it to work I get an error stating that "Unknown column 'reg_due' in 'field list'.

This is what I am looking for:
Registration Total: $20
Payment Total: $10
Total Owed: $10

//Here is the MySql Statment
SELECT sum(R.convention_amt + R.banquet_amt) AS reg_due, sum(P.payment) AS ttl_paid, reg_due - ttl_paid AS owes
FROM convention_registrations AS R, convention_payments AS P
WHERE R.account_nbr = acct_nbr AND P.account_nbr = acct_nbr
//The Error referes to "reg_due - ttl_paid AS owes"
//Here is the general Table layouts
Table convention_registrations
account_nbr, convention_amt, banquet_amt
Table convention_payments
account_nbr, payment

Sorry - one mistake in that one. Fixed here:
SELECT sum(R.convention_amt + R.banquet_amt) AS reg_due,
(select sum(P.payment) from convention_payments where account_nbr = acct_nbr) AS ttl_paid,

//Here is the MySql Statment
SELECT sum(R.convention_amt + R.banquet_amt) AS reg_due, sum(P.payment) AS ttl_paid, sum(R.convention_amt + R.banquet_amt) - sum(P.payment) AS owes
FROM convention_registrations AS R, convention_payments AS P
WHERE R.account_nbr = acct_nbr AND P.account_nbr = acct_nbr

Sometimes null's can affect the results - you should be able to get around that issue using COALESCE like this:

SELECT sum(COALESCE(R.convention_amt,0) + COALESCE(R.banquet_amt,0)) AS reg_due, sum(COALESCE(P.payment,0)) AS ttl_paid, sum(COALESCE(R.convention_amt,0) + COALESCE(R.banquet_amt,0)) - sum(COALESCE(P.payment,0)) AS owes
FROM convention_registrations AS R, convention_payments AS P
WHERE R.account_nbr = acct_nbr AND P.account_nbr = acct_nbr

> Ok, I added a payment of $ 50 and this it what the results were.

Do you still need a result when there's no payments for a registration? If so, you'll need a left outer join, not an inner join like you've got.

SELECT sum(COALESCE(R.convention_amt,0) + COALESCE(R.banquet_amt,0)) AS reg_due, sum(COALESCE(P.payment,0)) AS ttl_paid, sum(COALESCE(R.convention_amt,0) + COALESCE(R.banquet_amt,0)) - sum(COALESCE(P.payment,0)) AS owes
FROM convention_registrations AS R left outer join convention_payments AS P on R.account_nbr = acct_nbr AND P.account_nbr = acct_nbr

Sorry the code you sent at 1126 resulted in 12 rows. The code sent at 1127 had the same results as above. The idea is so that when the user logs in, they will see that they have either not sent money in, or we have not processed their checks.

Can you post the results of this query, to show what data we're dealing with?

SELECT R.convention_amt, R.banquet_amt, P.payment
FROM convention_registrations AS R, convention_payments AS P
WHERE R.account_nbr = acct_nbr AND P.account_nbr = acct_nbr

SELECT sum(P.payment) AS ttl_paid, (SELECT sum(R.convention_amt + R.banquet_amt) FROM convention_registrations AS R WHERE account_nbr = acct_nbr) AS reg_due, reg_due - ttl_paid AS owes FROM convention_registrations AS R, convention_payments AS P
WHERE account_nbr = acct_nbr

SELECT sum(R.convention_amt + R.banquet_amt) AS reg_due,
(select sum(P.payment) from convention_payments where account_nbr = acct_nbr) AS ttl_paid,
(sum(R.convention_amt + R.banquet_amt) - (select sum(P.payment) from convention_payments where account_nbr = acct_nbr)) AS owes
FROM convention_registrations AS R
WHERE R.account_nbr = acct_nbr

SELECT sum(R.convention_amt + R.banquet_amt) AS reg_due,
(select sum(P.payment) from convention_payments where account_nbr = acct_nbr) AS ttl_paid,
(sum(R.convention_amt + R.banquet_amt) - (select sum(payment) from convention_payments where account_nbr = acct_nbr)) AS owes
FROM convention_registrations AS R
WHERE R.account_nbr = acct_nbr

Deprecated and Headed for the Dustbin
By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems. Â This article discusses one of those, called register_globals. Â It is a thing you do not want. Â â€¦

Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will wâ€¦