SQL - AS - table doesn't exist - 1146

久未见 提交于 2019-12-24 08:23:00

问题


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.


回答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.




回答2:


I think you have your column incorrect...

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

should be

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



回答3:


@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.



来源:https://stackoverflow.com/questions/5263876/sql-as-table-doesnt-exist-1146

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!