Note that there are some explanatory texts on larger screens.

plurals
  1. POGet title of the latest record on a group
    primarykey
    data
    text
    <p>I'm doing a self join and I have the following query:</p> <pre><code>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 </code></pre> <p>But I'm getting an error: </p> <pre><code>MySQL said: #1111 - Invalid use of group function </code></pre> <p>What I'm trying to do is to get the title of the latest record of a group in the table.</p> <p>EDIT:</p> <pre><code>+-----------------------------------------------------------------------+ | 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 | +-----------------------------------------------------------------------+ </code></pre> <p>Now, I want a result:</p> <pre><code>+-----------------------------------------------------------------------+ | 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 | +-----------------------------------------------------------------------+ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload