tags:

views:

7

answers:

1

I have a table in which i have 3 columns with words.The words in col 1 have related words in col 2 and then in col3. If i select a value from the first column related words in the second column have to be displayed and in case it has related words in third column those words should also be displayed. How is this possible in mysql?

+1  A: 

It is a little unclear what you mean by "related words" but it sounds like you might benefit from redoing your database.

Have a table called 'words' composed of a primary key field , and a varchar field 'word' for the words themselves (1 word per row).

Have a second table called word_relationships

composed of:

word_id,related_id

word ID references your target word by igts primary key. related_id references words (by their ID) your target is related to.

this allows you to have an unlimited amount of words and pull what you need. If order is important, add a 'position' field to the world_relationships table.

cgr