开发者

MySql:Auto population

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 f开发者_StackOverflowirst 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜