举例说明用sql查询表1的某字段值包含在表2的某字段值内容里的记

原创
2016-06-07 15:13:52 2272浏览

现有表table1和表table2,表结构如图 table1: table2: 现在的目的是从table1中查询出所有stus为0,而且对应fid的包含在table2的fids字段的里的所有记录。 实现的sql语句如下: select * from table1 where exists( select fid from table2 where stus='0'

现有表table1和表table2,表结构如图

table1: table2:


现在的目的是从table1中查询出所有stus值为0,而且对应fid的值包含在table2的fids字段的值里的所有记录。

实现的sql语句如下:

select * from table1
where exists(
select fid from table2
where stus='0'
and table2.fids like'%' || table1.fid || '%')

查询的结果如下




声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。