Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,992
    Thanks
    120
    Thanked 76 Times in 76 Posts

    group_concat contence of column - extracting keywords

    say I have this in table
    Code:
    thing 
    real thing

    I dont see any easy way to get this out:

    'real,thing'

    group_concat (distinc field) will not do it. Would give me 'thing, real thing'

    Any thought ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    134
    Thanks
    0
    Thanked 32 Times in 32 Posts
    Can you rephrase your question? I don't understand what you want to do.

    If your table looks like this, what do you want your output to be?

    Code:
    column_name
    --------------
    one
    two three

  • #3
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,992
    Thanks
    120
    Thanked 76 Times in 76 Posts
    in that case:
    one,two,three

    that is, I want group concat(distinct)
    and on top of that distinct words.
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,211
    Thanks
    80
    Thanked 4,571 Times in 4,535 Posts
    I don't think there is any easy way to do this in SQL.

    There is no easy way for a SQL query to know that the value in one record is a part of the value in another record.

    If there truly are only two records in your result set it wouldn't be too hard, but what if there were 200 records?

    And KuriosJon asked you what you wanted to get from
    Code:
    column_name
    --------------
    one
    two three
    And you answered
    Code:
    one,two,three
    That's even tougher, as now you are asking SQL to recognize that "two three" is two separate words, split up those words, and then group_concat them back to get the commas between them.

    CAN this be done? Sure. Anything *CAN* be done. But it would be a messy Stored Procedure that would probably need to use a cursor.

    I think you would be better off just getting "thing,real thing" via group_concat and then using PHP coding to consolidate that down to "thing,real".
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •