SQL-AS-表不存在-1146

SQL-AS-表不存在-1146

问题描述:

我的查询是:

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'不存在

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

我如何使其起作用? 谢谢.

How can I make it work? Thank you.

似乎您想选择最后一个"pid",以"date"为单位,其中s.mid ='2'

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

尝试一下(找出pid的来源并更正第一行之后)

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.