举例说明用sql查询表1的某字段值包含在表2的某字段值内容里的记录(附表结构图)
现有表table1和表table2,表结构如图
table1: table2:
现在的目的是从table1中查询出所有stus值为0,而且对应fid的值包含在table2的fids字段的值里的所有记录。
实现的sql语句如下:
select * from table1
where exists(
select fid from table2
where stus='0'
and table1.fids like'%' || table2.fid || '%')
查询的结果如下
- 2楼lucherr昨天 17:56
- ^ ^
- 1楼wang_yunjiang昨天 17:50
- 嗯不错!