Jump to content

Grouping by text length.


Averen

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.