Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-12-2012, 11:11 AM   PM User | #1
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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
BubikolRamios is offline   Reply With Quote
Old 02-12-2012, 12:36 PM   PM User | #2
KuriosJon
Regular Coder

 
Join Date: Jan 2012
Posts: 134
Thanks: 0
Thanked 32 Times in 32 Posts
KuriosJon is on a distinguished road
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
__________________
Roundabout Time Tracking
KuriosJon is offline   Reply With Quote
Old 02-12-2012, 05:06 PM   PM User | #3
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
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
BubikolRamios is offline   Reply With Quote
Old 02-13-2012, 06:27 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is online now   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:58 AM.


Advertisement
Log in to turn off these ads.