How do I select the first odd/even numbered primary key in a SQL database -


let's have simple table of values (almost key/value store). there primary key on table indexed , auto incremented. example here rows:

 [id]  [columna]   [columnb]   2     "data"    "more data"       3     "data"    "more data"       4     "data"    "more data"       7     "data"    "more data"   8     "data"    "more data"   11    "data"    "more data" 

there might 1000+ values in table.

let's want select row containing first odd numbered id in table. in case should return row 3 "data" "more data".

also how select first numbered id?

thanks much

select id table mod(id, 2) = 1 order id limit 0, 1 

use mathematical function 13 % 2 = 1 (sorry, don't know how in english, devide modulo). mysql function mod


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -