开发者

SQL - AS - table doesn't exist - 1146

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 = (SEL开发者_运维百科ECT MAX(date) FROM temp)

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

How can I make it work? Thank you.


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.


I think you have your column incorrect...

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

should be

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜