sql - if there is duplicate data the how to select the specific one in mysql -


i have table program_data in mysql database.

  _id     value   1        0    2        1   3        3   4        1   5        1   6        1   7        6   8        1   9        2 

now here want select single row value 1. twist is, wanted select third 1 bottom in value column.

the output like:

_id = 5  value = 1   

i have written query like:

 select distinct * program_data  value= 1 order value desc                   limit  3;  

but in case last 3 rows, want 1 row third value 1 bottom.

if wan third 1 "bottom", assuming _id determines ordering:

select d.* data d value = 1 order _id desc limit 2, 1; 

this uses offset in limit clause.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -