简体   繁体   English

从具有不同列数的两个表中选择

[英]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.

相关问题 select子句从联接表的不同列中求值并返回值 - select clause evaluates and return value from different columns of joined tables 通过两个针对两个不同表中不同列数的选择查询将数据添加到一个表中 - Adding data into one table from two select queries targeting different number of columns from two different tables 从具有不同列数的两个表中选择* - select * from two tables with different # of columns SQL select 两个表没有相似的条目和不同的列数 - SQL select two tables with no similar entry and different number of columns SQL 除了 Select 两个表的列数不同 - SQL Except Select with different number of columns in two tables MySQL JOIN / UNION SELECT两个表中具有不同列数的所有行 - MySQL JOIN / UNION SELECT all rows from two tables with different number of columns 从两个不具有相同列数的不同表中选择数据 - Select data from two different tables that dont have the same number of columns 从两个表 mysql 的两列中选择不同的值 - Select the different value from two columns from two tables mysql 在两个不同的列中组合具有ID的联接表的方法? - Method to combine joined tables with id in two different columns? 来自不同表的联接列,并获得联接列的总数 - Joining Columns From different tables, and to get the total of the joined columns
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM