Averen Posted October 8, 2006 Share Posted October 8, 2006 Hey there,I currently have a table [table][tr][td]id[/td][td]name[/td][td]text[/td][/tr][tr][td]1[/td][td]var1[/td][td]text[/td][/tr][tr][td]2[/td][td]var1[/td][td]moretext[/td][/tr][tr][td]3[/td][td]var2[/td][td]text[/td][/tr][tr][td]4[/td][td]var2[/td][td]moretext[/td][/tr][/table]Now I want to group this table by name, but have the group have the longest 'text' eg[table][tr][td]name[/td][td]text[/td][/tr][tr][td]var1[/td][td]moretext[/td][/tr][tr][td]var2[/td][td]moretext[/td][/tr][/table]Anyone have any ideas? Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/ Share on other sites More sharing options...
Firemankurt Posted October 9, 2006 Share Posted October 9, 2006 I'm sorry. I tried a number of things but this is as close as I can get so far.It does not work yet but it may stimulate an idea for someone else.The subquery works by itself but seems to fail as a subquery.[code]SELECT `name` , CHAR_LENGTH(`name`) AS `Length` FROM `table` WHERE `Length` IN ( SELECT MAX(CHAR_LENGTH(`Length`)) FROM `table` ) [/code] Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-106066 Share on other sites More sharing options...
fenway Posted October 9, 2006 Share Posted October 9, 2006 Are you running a version with subquery support (4.1+)? Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-106110 Share on other sites More sharing options...
Averen Posted October 9, 2006 Author Share Posted October 9, 2006 That I am. :) Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-106292 Share on other sites More sharing options...
fenway Posted October 10, 2006 Share Posted October 10, 2006 Then I don't know what you mean by "fails". Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-106880 Share on other sites More sharing options...
Averen Posted October 11, 2006 Author Share Posted October 11, 2006 Oh you were asking the guy that posted the SQL not me, haha.Anyway, that sql doesn't work for me either. Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-107301 Share on other sites More sharing options...
fenway Posted October 11, 2006 Share Posted October 11, 2006 You can probably do with with a derived table that gets the max length entry by name, and then JOINing in the original table. Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-107561 Share on other sites More sharing options...
Averen Posted October 12, 2006 Author Share Posted October 12, 2006 Ok I'll try that, thanks. Link to comment https://forums.phpfreaks.com/topic/23348-grouping-by-text-length/#findComment-107774 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.