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

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

WBOY
WBOYOriginal
2016-06-07 15:13:522821Durchsuche

现有表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:                                                              

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

现在的目的是从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 || '%')

查询的结果如下

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



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn