I have two tables, which I need to join by one column and is indexed in both the tables. But both the columns of those two tables, consist of same values repeating many a times. So the columns used for joining look something like this:
TableA.column2 Table B.column3
1 2
1 2
1 1
4 1
4 4
5 3
Now as far as I understand from BNL and BKA algorithms, they would take on the rows from table A one by one and look for the matching records in table B. But it would not make any sense to look for the matching records for the second row of this A table because the value is again “1” for which, it already has matching records from the operations performed for row1 that has the same column value.
It is just the wastage of time and resources. It would have been better if it could pick the distinct values in Table A.column2 and then look for the matching records in table B.column3 and then just club them all together.
Can you please tell me some another algorithm for joining operations in mysql that does the kind of thing that I am talking about.??
By using Distinct will ensure uniqueness in ultimate columns returned. Now, doing a left-join will ensure all from the TableA… However, if no records matched in tableB, the COALESCE() will return a value of 0 instead of null — thus indicating no record in the tableB file.
From your data, you should get something like