I would like to get data from 2 mysql tables.
Table tbl_1:
Table tbl_2:
I tried this:
SELECT `tbl_2`.*
FROM `tbl_1`
LEFT JOIN `tbl_2` ON `tbl_1`.invoiceID = `tbl_2`.invoiceID
WHERE `tbl_1`.customerID = "463";
My result:
The results looks good but not perfect.
I get many null rows which are not be in my result.
only the first both rows should be in the result.
Where is my fault?
>Solution :
The LEFT JOIN keyword returns all records from the left table tbl_1, and the matching records from the right table tbl_2. So change the order of the tables
SELECT `tbl_2`.*
FROM `tbl_2`
LEFT JOIN `tbl_1` ON `tbl_1`.invoiceID = `tbl_2`.invoiceID
WHERE `tbl_1`.customerID = '463';


