Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL中LIKE与IN运算符的结合_Mysql - Fatal编程技术网

MySQL中LIKE与IN运算符的结合

MySQL中LIKE与IN运算符的结合,mysql,Mysql,我想做这样的事情: select * from table1 where name Like in (select name from table2 where id = '%123') 假设 select name from table2 where id = '%123' 结果是:abc123、def123、ghi123、 而表1包含的名称字段为AB-abc123-CD,CD-def123-HB,… 我该怎么做?如果我理解正确: select * from table1 where n

我想做这样的事情:

select * from table1 where name Like in (select name from table2 where id = '%123')
假设

select name from table2 where id = '%123' 
结果是:
abc123、def123、ghi123、

表1
包含的名称字段为
AB-abc123-CD,CD-def123-HB,…


我该怎么做?

如果我理解正确:

select * from table1 where name in (select name from table2 where id Like '%123')


我是否正确理解您的问题?

如果我正确理解您:

select * from table1 where name in (select name from table2 where id Like '%123')


我是否正确地理解了您的问题?

这可以在SQL Server上运行,我认为它也可以在MySQL上运行,可能只需稍作修改

select distinct t1.* from table1 t1
inner join table2 t2
on t1.name like '%' + t2.name + '%'
where t2.ShortString like '%123'

这可以在SQL Server上使用,我想它也可以在MySQL上使用,可能只需稍作修改

select distinct t1.* from table1 t1
inner join table2 t2
on t1.name like '%' + t2.name + '%'
where t2.ShortString like '%123'