mysql - SQL fetch the first of assigned list -
is possible fetch database row based on index of list given?
i have table lets call 'storage'. storage can have sorts of string value in it. list below present possible list of value in storage. don't know if present in table. want select first value found depending on order of list given
list:
- foo
- bar
- foobar
- barfoo
- oof
1.foo , 2.bar don't exist 3.foobar is. 3.foobar 1 want fetch.
hopefully clear enough in question.
thanks in advance.
select col your_table col in('foo','bar','foobar') order field(col, 'foo','bar','foobar') limit 1
the field()
function returns index of value in list.
Comments
Post a Comment