I have two table with big data in our MySQL database.
tbl_phonebook :
PB_ID CUST_NAME PHONE1 PHONE2 PHONE3 PHONE4
1 Richard 11111 12222 13333 14444
2 Maria 21111 22222 23333 24444
3 Robert 31111 32222 33333 34444
tbl_calllog :
LOG_ID CALL_TIME PHONENUMBER
1 2020-06-01 22222
2 2020-06-01 55555
3 2020-06-01 13333
How to get result like this with best performance :
LOG_ID CALL_TIME PHONENUMBER CUST_NAME
1 2020-06-01 22222 Maria
2 2020-06-01 55555 -
3 2020-06-01 13333 Richard
Thanks.
Please try this query:
I'm afaid current query is not the best performance, because mysql have to check conditions in all phone columns.
Setup a new table to map phone number to user like the following:
query will be:
the result and execution plan are as following: