举例说明用sql查询表1的某字段值包含在表2的某字段值内容里的记录(附表结构图)

来源:互联网 发布:站长交易第一平台源码 编辑:程序博客网 时间:2024/04/26 13:56

现有表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 || '%')

查询的结果如下




原创粉丝点击