MySql 无法在子查询中访问父级?
我收到错误消息,
Unknown column 'm.id' in 'on clause'
我的所有表都有一个名为 id 的字段。它似乎发生在我的子查询中。我在加入中使用 m.id。那么到底是怎么回事呢?我不应该能够访问该变量吗?如何从子查询访问 media.id? 和 not (select 1
部分是否正确?我试图排除该标签。
select m.id from media m
join tag_name as n0 on n0.title = @a0
join media_tag as t0 on t0.media_id=m.id AND t0.tag_id = n0.id
where 1
AND not (select 1 from tag_name as n1
join media_tag as t1 on t1.media_id=m.id AND t1.tag_id = n1.id
where n1.title = @a1)
order by m.id desc;
I get the error
Unknown column 'm.id' in 'on clause'
all my tables have a field called id. It appears to occur in my subquery. I use m.id in my join. So what the heck is going on? shouldnt i be able to access that var? how do i access media.id from my subquery? Also is the and not (select 1
part right? i am trying to exclude that tag.
select m.id from media m
join tag_name as n0 on n0.title = @a0
join media_tag as t0 on t0.media_id=m.id AND t0.tag_id = n0.id
where 1
AND not (select 1 from tag_name as n1
join media_tag as t1 on t1.media_id=m.id AND t1.tag_id = n1.id
where n1.title = @a1)
order by m.id desc;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 t1.media_id=m.id 的检查移至 where 子句,它可以工作(无论如何对我来说):
Move the check of t1.media_id=m.id to the where clause and it works (for me, anyway):