Bug #4150 Incorrect LEFT JOIN results

Submitted: 15 Jun 2004 18:35 Modified: 16 Jun 2004 0:20
Reporter: [ name withheld ] Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:3.23.58 OS:Linux (Linux Fedora v1.)
Assigned to: CPU Architecture:Any

[15 Jun 2004 18:35] [ name withheld ]
Description:
It appears that I am getting wrong results when I am running LEFT JOIN query on my table...

1. Checking number of rows in a table

mysql> select count(New_Customer_ID) from metafixCustomer;
+------------------------+
| count(New_Customer_ID) |
+------------------------+
|                   3308 |
+------------------------+
1 row in set (0.00 sec)

2. Just to make sure that all New_Customer_ID records are unique.

mysql> select count(distinct New_Customer_ID) from metafixCustomer;                                                                 
+---------------------------------+
| count(distinct New_Customer_ID) |
+---------------------------------+
|                            3308 |
+---------------------------------+
1 row in set (0.07 sec)

3. Now, running LEFT JOIN Query

mysql> SELECT COUNT(a.New_Customer_ID) from metafixCustomer AS a LEFT JOIN valueList AS b ON (a.New_Customer_ID = b.IdNumber);
+--------------------------+
| COUNT(a.New_Customer_ID) |
+--------------------------+
|                     3311 |
+--------------------------+
1 row in set (0.13 sec)

4. And now with distinct

mysql> SELECT COUNT(distinct a.New_Customer_ID) from metafixCustomer AS a LEFT JOIN valueList AS b ON (a.New_Customer_ID = b.IdNumber);
+-----------------------------------+
| COUNT(distinct a.New_Customer_ID) |
+-----------------------------------+
|                              3308 |
+-----------------------------------+
1 row in set (0.20 sec)

It doesn't seem right, LEFT JOIN without distinct should not allow any duplication of records in my metafixCustomer table.

Any comments?

Thanks

How to repeat:
Attached
[15 Jun 2004 20:23] [ name withheld ]
My bad, there were duplicated records in other table (should not be there), sorry about it.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.051 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.