[英]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). 首先,我有一个包含以下格式的字母数字的列:X12345678A(1个字母,8个数字和1个字母)。
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)
. 为了提高连接效率,您可以尝试在t1(col)
创建索引或在表达式t2(col1 || col2 || col3)
上创建索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.