【发布时间】:2021-11-19 01:20:52
【问题描述】:
我正在尝试删除包含项目的类别。
我有 4 张桌子:
类别
猫号
帖子
post_id
图片
image_post_id
标签
tag_post_id
我的 sql 查询是这样的,用于选择和取消链接图像:
SELECT * FROM categories, posts, images, comments, tags
WHERE catId = 25
AND post_catId = catId
AND image_post_id = post_id
AND comment_post_id = post_id
AND tag_cat_id = catId
AND tag_post_id = post_id
但它不显示帖子,类别中有超过 100 个帖子。
当我只搜索类别并发布时,它会显示全部。
【问题讨论】:
-
FROM categories, posts, images, comments, tags我相信这是 MySQL 中的交叉连接 -
不要这样写连接。使用正确的
join语法和on标准来了解连接的关联方式。where应该是返回什么,而不是加入关系。