1
SELECT table1.*,table2.*, table3.*
FROM table1, table2, table3
inner join 
 (
   select table1.id AS pid, max(table1.createtime) AS timestamp
   from table1 group by table1.id
 ) A on A.pid = table1.id AND A.timestamp = table1.createtime
WHERE table3.id = table1.id
ORDER BY table1.createtime;

我正在尝试仅获取 table1 中每个 id 的最后修改记录。

对于上述查询,我​​收到以下错误:

"%s:invalid identifier" for  "A.timestamp = table1.IDA2A2" this part.

请让我知道这个查询有什么问题。数据库是甲骨文。

4

1 回答 1

0

您的问题的一部分是您正在混合JOIN语法 - 您的查询同时使用逗号连接和 ANSI JOIN 语法。您需要正确加入表格:

SELECT t1.,t2., t3.* 
FROM table1 t1
INNER JOIN table2 t2
  on t1.id = t2.id
INNER JOIN table3 t3
  on t1.id = t3.id
inner join 
(
  select table1.id AS pid, max(table1.createtime) AS timestamp 
  from table1 
  group by table1.id
) A 
  on A.pid = t1.id 
  AND A.timestamp = t1.createtime 
ORDER BY t1.createtime;
于 2012-11-21T11:03:17.760 回答