Comments on: Selecting a specific non aggregated column data in GROUP BY https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by Blog by Shlomi Noach Thu, 12 Mar 2015 06:31:45 +0000 hourly 1 https://wordpress.org/?v=5.3.3 By: Is it possible to reduce a group to a row based on some criteria? | XL-UAT https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-311755 Thu, 12 Mar 2015 06:31:45 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-311755 […] See also my old post: Selecting a specific non aggregated column data in GROUP BY […]

]]>
By: guangnan https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-36718 Tue, 12 Apr 2011 11:02:18 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-36718 Smart. Thank you.

]]>
By: SQL: selecting top N records per group | code.openark.org https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-26379 Thu, 06 Jan 2011 10:49:13 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-26379 […] Selecting a specific non aggregated column data in GROUP BY […]

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-61 Mon, 01 Dec 2008 22:55:52 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-61 Shlomi: don’t be discouraged. It’s not about who’s first. I am pretty sure someone else figured this one out before me for that matter. They’d have to I guess, I mean, in the early days MySQL didn’t have subqueries and GROUP_CONCAT is an excellent device to work around subquery problems (in fact even now some queries that i’d rather solve with a subquery are often solved with better performance using these hacks)

Personally, I feel the hackishness of GROUP_CONCAT will be fulfilled when it gets a LIMIT clause. It may sound crazy but the idea is that it will make things like the groupwise MAX much more efficient if no time is spent building a large string concatenating all the entries – you could just do LIMIT 1 and save a lot of memory and avoid a warning about group_concat_max_len too.

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-60 Mon, 01 Dec 2008 20:03:01 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-60 Giuseppe – thanks!

Roland – good to see you here again, was a bit discouraged to have found your comment over there… Wasn’t stealing though 🙂
Thanks for the median query link – nice one!

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-59 Mon, 01 Dec 2008 19:30:48 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-59 Hi!

here’s another trick that uses the same device to calculate the median:

http://rpbouman.blogspot.com/2007/12/calculating-financial-median-in-mysql.html

]]>
By: Roland Bouman https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-58 Mon, 01 Dec 2008 19:05:33 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-58 Hi!

“UPDATE: Turns out an anonymous comment to Kristian Nielsen’s post suggested the same solution, about a week ago.”

Yeah, it’s mine. I try to sign those dreadful blog interfaces that require me to get an account, but apparently I forgot that time.

BTW – I made a mistake in that particular example, as I forgot to include a DESC for the ORDER BY (the problem was selecting the last version – not the first)

Roland Bouman
http://rpbouman.blogspot.com/

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-57 Mon, 01 Dec 2008 17:38:31 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-57 Toby,

Not so. It was cheaper on my testing benchmarks. I am careful to say “possible” because I cannot guarantee it will be cheaper to use this index on *any* table in *any* database under *any* circumstance, is all.

Shlomi

]]>
By: Toby https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-56 Mon, 01 Dec 2008 17:35:42 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-56 ‘Possibly’ cheaper? This may be no more than premature obfuscation, then.

]]>
By: shlomi https://shlomi-noach.github.io/blog/mysql/selecting-a-specific-non-aggregated-column-data-in-group-by/comment-page-1#comment-55 Mon, 01 Dec 2008 17:33:38 +0000 https://shlomi-noach.github.io/blog/?p=246#comment-55 Hi Toby,

This post presents an alternative which is very cheap with the right index, possibly cheaper than a JOIN alternative.

Shlomi

]]>