I have a MySQL varchar field with values like these:
'00007_1'
'00016_1'
'00016_2'
'00231_1'
'00326_3'
I'm looking for the best way to put this field in join with another table with a varchar field with values like these (I list those that match previous):
'7'
'16'
'16'
'231'
'326'
This is how I've made:
SELECT *
FROM R
INNER JOIN RC ON Trim(leading '0' from Substring(R.N_DEN,1,instr(R.N_DEN,'_')-1)) = RC.N_DEN
Anybody knows if there is a quicker and better performace solution?
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `RC` ADD INDEX `rc_idx_n_den` (`N_DEN`);
SELECT
*
FROM
R
INNER JOIN
RC
ON Trim(leading '0'
from
Substring(R.N_DEN,
1,
instr(R.N_DEN,
'_') - 1)) = RC.N_DEN