简体   繁体   中英

Select from two tables joined by different number of columns

I have two tables. In first, I have a column which holds an alphanumeric with this format: X12345678A (1 letter, 8 numbers and 1 letter).

In second table, I have the same field, but divided into three columns, the first containing the leading letter, the second containing the number, and the third containing the trailing letter.

My question: if I can't modify the table structure, how can I join both tables efficiently, ie, using an index?

Thank you in advance!

With string concatenation:

select . . .
from t1 join
     t2
     on t1.col = t2.col1 || t2.col2 || t2.col3;

For an efficient join, you can try an index on t1(col) or an index on the expression t2(col1 || col2 || col3) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM