472,351 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 software developers and data experts.

join query result difference between 3.23.49 and 4.0.13

hello,

i have what seems to me a very common operation i'm performing. i need to
find the balance on an invoice. i was not having any problems until the
production server was upgraded to mysql v4.0.13-standard for
pc-linux. there must be a better way to query for this information than
the method i'm using, since the result with v4.0 is not what i expected,
nor what i received with v3.23. i'm including sample data and queries with
my results. i've not been able to find any relevant messages in the list
archives. any comments are greatly appreciated.

========================================

here's the table structure and some sample data:

CREATE TABLE `billing` (
`invoice` mediumint(9) NOT NULL auto_increment,
`user_id` mediumint(9) NOT NULL default '0',
`invoice_date` date NOT NULL default '0000-00-00',
`amount` float NOT NULL default '0',
`timestamp` timestamp(14) NOT NULL,
PRIMARY KEY (`invoice`),
KEY `user_id` (`user_id`),
KEY `user_invoice` (`user_id`,`invoice`)
) TYPE=MyISAM COMMENT='invoices';
INSERT INTO `billing` VALUES (10000, 1, '2003-07-01', '500', 20030716092700);
INSERT INTO `billing` VALUES (10001, 1, '2003-07-03', '600', 20030716092807);

# --------------------------------------------------------

CREATE TABLE `billing_payment` (
`invoice` mediumint(9) NOT NULL default '0',
`amount_paid` mediumint(9) NOT NULL default '0',
`payment_status` varchar(15) NOT NULL default '',
`pending_reason` varchar(15) default NULL,
`payment_date` date default NULL,
`txn_id` varchar(20) default NULL,
`timestamp` timestamp(14) NOT NULL,
KEY `txn_id` (`txn_id`),
KEY `invoice` (`invoice`)
) TYPE=MyISAM COMMENT='payments on invoices';

INSERT INTO `billing_payment` VALUES (10000, 500, 'Completed', NULL,
'2003-07-02', '112233', 20030716092746);

========================================

here are the queries and results. note that query #1 gives the expected
(and desired) result on both versions, but query #2 only gives the expected
(and useful) result in v3.23. to give a brief explanation of the
difference between the queries: invoice 10000 has a payment against it,
while invoice 10001 has no payment records in the payment table.

=== v3.23.49

query #1
mysql> SELECT billing.invoice, SUM(amount_paid) AS paid, (billing.amount -
SUM(amount_paid)) AS balance FROM billing LEFT JOIN billing_payment ON (
billing.invoice=billing_payment.invoice ) WHERE billing.invoice=10000 GROUP
BY billing_payment.invoice;
+---------+------+---------+
| invoice | paid | balance |
+---------+------+---------+
| 10000 | 500 | 0 |
+---------+------+---------+
1 row in set (0.00 sec)

query #2
mysql> SELECT billing.invoice, SUM(amount_paid) AS paid, (billing.amount -
SUM(amount_paid)) AS balance FROM billing LEFT JOIN billing_payment ON (
billing.invoice=billing_payment.invoice ) WHERE billing.invoice=10001 GROUP
BY billing_payment.invoice;
+---------+------+---------+
| invoice | paid | balance |
+---------+------+---------+
| 10001 | 0 | 600 |
+---------+------+---------+
1 row in set (0.00 sec)

=== v4.0.13

query #1
mysql> SELECT billing.invoice, SUM(amount_paid) AS paid, (billing.amount -
SUM(amount_paid)) AS balance FROM billing LEFT JOIN billing_payment ON (
billing.invoice=billing_payment.invoice ) WHERE billing.invoice=10000 GROUP
BY billing_payment.invoice;
+---------+------+---------+
| invoice | paid | balance |
+---------+------+---------+
| 10000 | 500 | 0 |
+---------+------+---------+
1 row in set (0.01 sec)

query #2
mysql> SELECT billing.invoice, SUM(amount_paid) AS paid, (billing.amount -
SUM(amount_paid)) AS balance FROM billing LEFT JOIN billing_payment ON (
billing.invoice=billing_payment.invoice ) WHERE billing.invoice=10001 GROUP
BY billing_payment.invoice;
+---------+------+---------+
| invoice | paid | balance |
+---------+------+---------+
| 10001 | NULL | NULL |
+---------+------+---------+
1 row in set (0.00 sec)

NULL values in this result are not expected, nor are they helpful in
determining the invoice balance.

========================================

thanks again for any suggestions,

doug
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/my***********...ie.nctu.edu.tw

Jul 19 '05 #1
0 2358

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select...
2
by: Preston Landers | last post by:
Hello all. I am trying to write a query that "just" switches some data around so it is shown in a slightly different format. I am already able...
7
by: Greg | last post by:
I'm a quantitative securities analyst working with Compustat data (company fiscal reports and pricing feeds). My coworker came across a problem...
2
by: shumaker | last post by:
The query: SELECT BTbl.PKey, BTbl.Result FROM BTbl INNER JOIN ATbl ON BTbl.PKey = ATbl.PKey WHERE (ATbl.Status = 'DROPPED') AND...
5
by: jason.evans | last post by:
Hi there. I am having an intrigueing problem. I have a query which left joins another query to itself twice. The original query is derived...
1
by: Dot Net Daddy | last post by:
Hi, I am new to MS-SQL and I have a problem. Actually I have made similar queries on Oracle, but now I failed on MS Sql. First of all I am using...
6
by: dmonroe | last post by:
hi group -- Im having a nested inner join problem with an Access SQl statement/Query design. Im running the query from ASP and not usng the...
4
by: Jane T | last post by:
I appreciate how difficult it is to resolve a problem without all the information but maybe someone has come across a similar problem. I have an...
12
by: Chamnap | last post by:
Hello, everyone I have one question about the standard join and inner join, which one is faster and more reliable? Can you recommend me to use?...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.