php - 比较/检查 MySQL 中的两个表数据

标签 php mysql

我需要一些检查数据的帮助。我有两张 table 。我想检查 tableA 中的 file_name 是否包含在 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" />

最佳答案

确实我无法得​​到你想要的..但​​是这个查询可能会帮助你..

首先,表 A 中有文件名,并且该文件名包含在表 B 的内容中。因此,首先您要搜索该名称是否存在...之后您可以使用 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%'); 
    ";

关于php - 比较/检查 MySQL 中的两个表数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15922565/

相关文章:

javascript - Google PageSpeed Insights 问题 - 优先考虑可见内容

php - 如果 PHPMailer 失败,回退到本地 PHP 邮件功能

php - 统计Mysql表中的值

html - 根据一个公共(public)值连接表 : can't get to work

php - 在PHP中使用一组Mysql结果作为比较

分配有 and 的 PHP 数组

php - PDO begintransaction 与 MySQL 数据库锁

php - AJAX JQUERY 相关 :- How to call ajax on a ajax loaded page

javascript - 如何复制这个 JS 变量并更改使用的文本?

mysqld_safe UNIX 套接字文件的目录 '/var/run/mysqld' 不存在