sql与另一个表类似

sql与另一个表类似,sql,sql-like,Sql,Sql Like,我有两张表,第一张有:value1,value2,value3 第二:我有完整的地址 如何使用查询,如: 从表2中选择* “%table1.value1%table1.value2%table1.value3%”我认为存在满足您的需求: select t2.* from table2 t2 where exists (select 1 from table1 t1 where t2.address like concat('%', t1.v

我有两张表,第一张有:value1,value2,value3 第二:我有完整的地址

如何使用查询,如:

从表2中选择*

“%table1.value1%table1.value2%table1.value3%”
我认为
存在
满足您的需求:

select t2.*
from table2 t2
where exists (select 1
              from table1 t1
              where t2.address like concat('%', t1.value1, '%', t1.value2, '%', t1.value3, '%')
             );

也就是说,这样做的需要表明您的数据模型有问题。

我认为
存在
做您想要的:

select t2.*
from table2 t2
where exists (select 1
              from table1 t1
              where t2.address like concat('%', t1.value1, '%', t1.value2, '%', t1.value3, '%')
             );
也就是说,这样做的必要性表明您的数据模型有问题。

您可以试试这个吗

select * from table2 where address like '%table1.value1%' OR address like '%table1.value2%' OR address like '%table1.value3%'
但我认为您的数据模型应该规范化(2NF&3NF)。

您可以试试这个吗

select * from table2 where address like '%table1.value1%' OR address like '%table1.value2%' OR address like '%table1.value3%'

但是我认为您的数据模型应该规范化(2NF&3NF)。

REGEXP
可以用来匹配表1和表2的内容

select address, value1, value2, value3
from table1, table2 
where 
address REGEXP value1 and
address REGEXP value2 and
address REGEXP value3;
我觉得如果需要匹配硬编码值,最好使用
like

select address from table1 where address like '%staticvalue%'

参见

REGEXP
中的一个实现示例,该示例可用于匹配表1和表2的内容

select address, value1, value2, value3
from table1, table2 
where 
address REGEXP value1 and
address REGEXP value2 and
address REGEXP value3;
我觉得如果需要匹配硬编码值,最好使用
like

select address from table1 where address like '%staticvalue%'

参见

sql-like
you-Gordon,它非常喜欢你+1:-)
sql-like
you-Gordon,它非常喜欢你+1:-)你想要连接字符串(
'%'| | table1.value1 | |'%'| table1.value2 |'%'| | | | | | table1.value3 |'%
在标准sql中)。您使用的是哪种DBMS?您想连接字符串(
“%”| | | table1.value1 | |‘%”‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘‘。您使用的是哪种数据库管理系统?