简体   繁体   English

SQL LIKE 从另一个表

[英]SQL LIKE from another table

I have two tables:我有两张桌子:

Table1 with the column customerName in string:表 1,字符串中包含 customerName 列:

1,2,3,101,102,customerA,customerB.

Table 2 with the changeID in string:00001,00002,00101,customerA.表 2 中的 changeID 字符串为:00001,00002,00101,customerA。

Now I want to join these two tables, because I know changeID 00001 is customer 1, changeID 00101 is customer 101 and changeID customerA is off course customerA, but due to the zeroes I tried to use LIKE but failed.现在我想加入这两个表,因为我知道 changeID 00001 是客户 1,changeID 00101 是客户 101,而 changeID customerA 是客户 A,但是由于零我尝试使用 LIKE 但失败了。

Do you guys have Idee how to join these two tables?你们有Idee如何加入这两个表吗?

You can use an old "where join":您可以使用旧的“where join”:

Select Table1.*, Table2.*
From Table1, Table2
Where Table1.ID = Val(Table2.ChangeID)

or:或者:

Select Table1.*, Table2.*
From Table1, Table2
Where Right("0000" & Table1.ID, 5) = Table2.ChangeID

If that is too slow, write either of the tables to temporary table where the final ID and ChangeID will have matching data types.如果这太慢,请将其中一个表写入临时表,其中最终 ID 和 ChangeID 将具有匹配的数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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