Yakhoob Yakhoob - 1 year ago 106
MySQL Question

Left join returning total records in SQL instead of matching records

I've written a Left join between two tables. My table structure is

SELECT D.DLNOPK, D.STARTDT
FROM DEALDETAILS D
LEFT JOIN
DEALCUSTOMERDETAILS P
ON P.DLNO = D.DLNOPK
WHERE P.CUSTOMERID = 'ABCD';


Actually the total number of rows in Deal details is 100, but even after writing the where clause, it returns 100 rows.

My table structure is

DEALDETAILS



DLNOPK | STARTDT

DEALCUSTOMERDETAILS



DLNO | CUSTOMERID

What is wrong with the where clause?

Answer Source

Here the total query you ask ^^

SELECT  D.DLNOPK, D.STARTDT
FROM    DEALDETAILS D
LEFT JOIN   DEALCUSTOMERDETAILS P
ON    D.DLNOPK =  P.DLNO
WHERE P.CUSTOMERID = 'ABCD'; 

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download