gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 08:33:28 24 4
gpt4 key购买 nike

我需要一些检查数据的帮助。我有两张 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com