mysql - list out most matching ids first, others later -


currently developing "different" style of search. have following table

id     keywords 1      apple orange mango grapes watermelon 2      apple mango 3      orange 4      orange grapes apple 5      grapes 6      grapes mango apple 7      watermelon apple orange 

and search field text-box ore or more fruit names can mentioned, example

 apple grapes 

i need results in following manner: first search first fruit (apple) in above table, matching ids be

 1, 2, 4, 6, 7 

then search second fruit (grapes) in above table, matching ids be

 1, 4, 5, 6 

as can see above, apple , grapes appeared @ following ids

 1, 4, 6 

i need query shell give me matching ids first, other later

 1, 4, 6, 2, 7, 5 

if doing parsing in php each word, can try:

select k.* table k order (find_in_set($keyword1, replace(keywords, ' ', ',')) > 0 +           find_in_set($keyword2, replace(keywords, ' ', ',')) > 0 +           find_in_set($keyword3, replace(keywords, ' ', ',')) > 0          ) desc; 

however, should not storing data in list (space delimited or comma delimited). instead, should have junction table 1 row per id , keyword.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -