0

我需要一点帮助来检查数据。我有两张桌子。我想检查 file_name intableA是否包含在tableB. 如果不是,那么结果就是file_name这个。

select * from tableA;
| id | file_name
+---+----------
|  1 | apple.jpg 
|  2 | green_apple.jpg
|  3 | red_apple.jpg
|  4 | apple1.jpg
|  5 | apple-juce.jpg

////////////////////////////////////////////

select * from tableB;

| id |  title   |content 
+----+----------+--------
|  1 |  title1  | <img style="border:1px dotted;width:463px;height:611px;margin-left:20px;float:right;padding:3px;" src="image/green_apple.jpg" /><p>Lorem Ipsum is simply <b>dummy text</b> of the printing and typesetting industry. </p>
|  2 |  title2  | <p>Lorem Ipsum is simply <b>dummy text</b> of the printing and typesetting industry. </p><img style="border:1px dotted;width:463px;" src="image/apple.jpg" />
|  3 |  title3  | <img style="border:1px dotted;width:463px;" src="image/apple.jpg" /><p>Lorem Ipsum is simply <b>dummy text</b> of the printing and typesetting industry. </p><img style="border:1px dotted;width:463px;" src="image/apple.jpg" />
|  4 |  title4  | <img style="border:1px dotted;width:463px;" src="image/red_apple.jpg" /><p>Lorem Ipsum is simply <b>dummy text</b> of the printing and typesetting industry. </p><img style="border:1px dotted;width:463px;" src="image/apple.jpg" />
|  5 |  title5  | <p>Lorem Ipsum is simply <b>dummy text</b> of the printing and typesetting industry. </p><img style="border:1px dotted;width:463px;" src="image/apple1.jpg" />
4

1 回答 1

2

我不能得到你想要的东西。但是这个查询可能对你有帮助。。

首先,您在 tableA 中有文件名,并且该文件名包含在 tableB 的内容中。因此,首先您要搜索该名称是否存在...之后您可以使用 NOT IN 来选择您想要的数据(如果 tableB 中不存在)。

    "select file_name from tableA where file_name like '%$search%' 
    AND file_name NOT IN (select content from tableB where file_name like '%$search%'); 
    ";
于 2013-04-10T10:15:01.663 回答