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'