sql - MySQL - Join tables, retrieve only Max ID -



sql - MySQL - Join tables, retrieve only Max ID -

i've seen solutions similar on other posts, i've been having issue applying specific problem.

here initial join:

select service_note_task, comment_id, comment service_note_task left bring together service_note_task_comments on service_note_task.service_note_task_id = service_note_task_comments.service_note_task_id;

which results in:

+-----------------------------+------------+--------------+ | service_note_task | comment_id | comment | +-----------------------------+------------+--------------+ | service note task 3 | 25 | comment | | service note task 3 | 26 | comment blah | | service note task 3 | 36 | aaa | | service note task 2 | 13 | awesome comm | | service note task 1 | 12 | cool comm | +-----------------------------+------------+--------------+

but each service_note_task, need 1 row representing comment highest comment_id, this:

+-----------------------------+------------+--------------+ | service_note_task | comment_id | comment | +-----------------------------+------------+--------------+ | service note task 3 | 36 | aaa | | service note task 2 | 13 | awesome comm | | service note task 1 | 12 | cool comm | +-----------------------------+------------+--------------+

i figure utilize max in sub-select statement narrow downwards results want them. how can incorporate statement these results?

for reference, known "groupwise-maximum"

http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html

sql max greatest-n-per-group

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -