sql - MySQL, grouping words and saving them to two other tables -


have 3 tables:

products (relevant columns: id, name) wordgroups (relevant columns: id, wordgroup) productwordgroups (relevant columns: wordgroupid, productid) 

now separate each products.name wordgroups of 1-3 words this:

name = "a b c d e" =>  wordgroups = "a", "a b", "a b c", "b", "b c", "b c d", "c", "c d", "c d e", etc. 

these wordgroups must saved wordgroups.wordgroup if don't exist in table already.

finally, many-to-many relation between table products , table wordgroups must saved productwordgroups if relation doesn't exist in table already.

guess can done nasty sql query, far haven't been able trick mysql doing it.

thanks.

i have solved second part of problem you, if extract letters separate rows given name.

the extracting need done in procedure.

my code, letters input table , letter column:

select * letters union select a.letter||' '||b.letter letter letters a,letters b  a.letter<b.letter union select a.letter||' '||b.letter||' '||c.letter letter letters a,letters b,letters c  a.letter<b.letter , b.letter<c.letter 

this input:

a b c d e 

this output:

a b c d e b c d e b c b d b e c d c e d e b c b d b e c d c e d e b c d b c e b d e c d e 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -