SQL - AS - 表不存在 - 1146

发布于 2024-10-21 21:23:18 字数 277 浏览 7 评论 0原文

我的查询是:

SELECT temp.pid FROM 
(SELECT postid, date FROM swapping AS s, post AS p 
WHERE s.mid='2' AND p.postid=s.postid)  AS temp 
WHERE temp.date = (SELECT MAX(date) FROM temp)

我收到 #1146 - 表“databasename.temp”不存在

我怎样才能使其工作? 谢谢。

My query is:

SELECT temp.pid FROM 
(SELECT postid, date FROM swapping AS s, post AS p 
WHERE s.mid='2' AND p.postid=s.postid)  AS temp 
WHERE temp.date = (SELECT MAX(date) FROM temp)

I receive #1146 - Table 'databasename.temp' doesn't exist

How can I make it work?
Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你没皮卡萌 2024-10-28 21:23:18

看起来你想选择最后一个“pid”,就“日期”而言,其中 s.mid='2'

尝试这个(在你弄清楚 pid 来自哪里并更正第一行之后)

SELECT [s? or maybe p?].pid
FROM swapping s INNER JOIN post p ON p.postid=s.postid
WHERE s.mid = '2'
ORDER BY date DESC
LIMIT(0,1)

你可能还需要按行排序中的日期列的别名。

It seems like you want to select the last "pid", in terms of "date", where s.mid='2'

Try this (after you figure out where pid comes from and correct the first line)

SELECT [s? or maybe p?].pid
FROM swapping s INNER JOIN post p ON p.postid=s.postid
WHERE s.mid = '2'
ORDER BY date DESC
LIMIT(0,1)

You might also need to alias the date column in the order by line.

南薇 2024-10-28 21:23:18

我认为你的专栏不正确......

SELECT temp.pid  FROM  ( SELECT  postid, ...

应该是

SELECT temp.postid  FROM  ( SELECT  postid, ...

I think you have your column incorrect...

SELECT temp.pid  FROM  ( SELECT  postid, ...

should be

SELECT temp.postid  FROM  ( SELECT  postid, ...
穿透光 2024-10-28 21:23:18

@DRapp 至少击中要害。您没有在您引用为临时的子选择中选择“pid”(如果该列存在于交换表或帖子表中),因此它会在那里引发某种类型的错误。

@DRapp hit the nail on the head at least. You haven't selected 'pid' (if that column exists in either the swapping or post table) in your sub selection that your referring to as temp so it would throw some type of error there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文