我需要一个帮助。我需要检查一个表的列数据是否存在于使用PHP和MySQL的同一数据库中的另一个表中。我正在解释下面的表。
db_gallery:
id subcat_id image
1 60 123.png
2 60 234.png
3 58 456.png
db_special_image
id subcat_id name gallery_image
1 60 aaa 123.png
2 58 bbb 456.png
在这里,我需要检查db_special_image
表中是否存在任何图库图像。我需要查看subcat_id
。假设我知道subcat_id=60
。我需要检查db_gallery
表中属于subcat_id=60
的{{1}}表中的任何图像是否存在于db_special_image
表中。如果有任何图像,那么它将返回1否则为0.我需要查询。请帮帮我。
答案 0 :(得分:1)
您可以使用Mysql INNER JOIN
加入两个表格。
然后使用count('某事'); if it's !=0, echo "1"; else echo "0"
答案 1 :(得分:0)
显示db_gallery中存在的图像以及db_special_image ...
内部查询错误?
SELECT * from db_gallery WHERE db_gallery.image IN (SELECT gallery_image FROM db_special_image WHERE db_gallery.subcat_id = db_special_image.subcat_id)
<强>加入强>
SELECT * from db_gallery INNER JOIN db_special_image ON db_gallery.subcat_id = db_special_image.subcat_id AND db_gallery.image=db_special_image.gallery_image
答案 2 :(得分:0)
使用x2 = x[np.ix_(np.arange(x.shape[0]), k.flat, i.flat, j.flat)].reshape((x.shape[0], ) + k.shape + i.shape + j.shape)
x2.shape
(2, 12, 1, 12, 25, 12, 25)
np.all(x1 == x2)
True
INNER JOIN关键字选择两个表中具有匹配值的记录。 mysql INNER JOIN
ON db_gallery.subcat_id = db_special_image.subcat_id
如果num_rows count大于0 SELECT name,db_gallery.subcat_id,image from db_gallery INNER JOIN db_special_image ON db_gallery.subcat_id = db_special_image.subcat_id
其他echo "1";