如何使用子字符串检索记录 [英] How do I retrieve records using substrings
问题描述
请问如何从两个表Table_A和Table_B中检索记录,其中Table_B的列(colWord)中的数据是Table_A的列(colC)中的数据的子字符串?即。 SQL服务器
例如。
表A
id | colC
--------
1 |明天是星期三
2 |我会在那里
3 |这是一个例子
Table_B
id | colWord
--------------
1 |周三
2 |那里
3 |例子
4 |来
使用
please how do i retrieve records from two tables, Table_A and Table_B, where data in column(colWord) of Table_B is a substring of data in column(colC) of Table_A? ie. SQL server
Eg.
Table A
id|colC
--------
1 |tomorrow is wednesday
2 |I will be there
3 |this is an example
Table_B
id | colWord
--------------
1 |wednesday
2 |there
3 |example
4 |come
using
select colC,colWord ....
语句应该返回
colC | colWord
------------------------------------- ----------
明天是星期三|星期三
我会在那里|那里
这是一个例子。例子
我尝试过:
要使用的过滤器是我的问题
statement should return
colC | colWord
-----------------------------------------------
tomorrow is wednesday |wednesday
I will be there |there
this is an example |example
What I have tried:
The filter to use is my problem
推荐答案
如果数据足够小,那么只需在连接中使用相似的比较:
if the data is small enough then just use a like comparison in the join:
Select * from Table_A a
inner join Table_B b on a.colC like '%'+b.colWord+'%'
这对于大数据来说太糟糕了!
如果您需要对大数据的查询有解决方案
This will be terrible for large data!
If you need a query for large data there are solutions
这篇关于如何使用子字符串检索记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!