SQL - AS - table不存在- 1146

时间:2021-10-17 08:24:40

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

我收到#1146 -表格'databasename。临时的不存在

How can I make it work? Thank you.

我如何让它工作?谢谢你!

3 个解决方案

#1


4  

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

似乎您想要选择最后一个pid,用“date”表示,其中s.mid='2'

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

试试这个(在您确定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)

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

您可能还需要按行对日期列进行别名。

#2


1  

I think you have your column incorrect...

我想你的专栏写错了……

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

should be

应该是

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

#3


0  

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

@DRapp至少击中了要害。您还没有在您的子选择中选择“pid”(如果该列存在于交换或post表中),您将其引用为temp,因此它将在那里抛出一些类型的错误。

#1


4  

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

似乎您想要选择最后一个pid,用“date”表示,其中s.mid='2'

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

试试这个(在您确定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)

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

您可能还需要按行对日期列进行别名。

#2


1  

I think you have your column incorrect...

我想你的专栏写错了……

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

should be

应该是

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

#3


0  

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

@DRapp至少击中了要害。您还没有在您的子选择中选择“pid”(如果该列存在于交换或post表中),您将其引用为temp,因此它将在那里抛出一些类型的错误。