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:

  1. foo
  2. bar
  3. foobar
  4. barfoo
  5. 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

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -