自己結合を実行していますが、次のクエリがあります。
select
max( wf1.id ) as latest_id,
max( wf1.created ) as latest_created,
wf1.id, wf1.created, wf1.title,
wf2.id, wf2.created, wf2.title
from
worksheet_forms wf1
join
worksheet_forms wf2
on
max( wf1.id ) = wf2.id
where
wf1.company_id = '000002'
group by
wf1.generated_id
しかし、エラーが発生します:
MySQL said:
#1111 - Invalid use of group function
私がやろうとしているのは、テーブル内のグループの最新レコードのタイトルを取得することです。
編集:
+-----------------------------------------------------------------------+
| id | generated_id | company_id | title | created |
+-----------------------------------------------------------------------+
| 1 | aaajdfie34343 | 000002 | ws1 | 2012-02-08 17:27:30 |
| 2 | aaajdfie34343 | 000002 | ws2 | 2012-02-09 17:27:30 |
| 3 | aaajdfie34343 | 000002 | ws3 | 2012-02-10 17:27:30 |
| 4 | bbbjdfie34343 | 000002 | ws4 | 2012-02-11 17:27:30 |
| 5 | bbbjdfie34343 | 000002 | ws5 | 2012-02-12 17:27:30 |
| 6 | bbbjdfie34343 | 000002 | ws6 | 2012-02-13 17:27:30 |
| 7 | bbbjdfie34343 | 000002 | ws7 | 2012-02-14 17:27:30 |
| 8 | cccjdfie34343 | 000002 | ws8 | 2012-02-15 17:27:30 |
| 9 | cccjdfie34343 | 000002 | ws9 | 2012-02-16 17:27:30 |
+-----------------------------------------------------------------------+
今、私は結果が欲しいです:
+-----------------------------------------------------------------------+
| id | generated_id | company_id | title | created |
+-----------------------------------------------------------------------+
| 3 | aaajdfie34343 | 000002 | ws3 | 2012-02-10 17:27:30 |
| 7 | bbbjdfie34343 | 000002 | ws7 | 2012-02-14 17:27:30 |
| 9 | cccjdfie34343 | 000002 | ws9 | 2012-02-16 17:27:30 |
+-----------------------------------------------------------------------+