sql - getting last record from the database with some conditions -


my table structure

recordid         mobilenumber         month            year          yearmonth 101               9900000000          4                2013           20134 102               9900000000          3                2013           20133 103               9900000000          1                2013           20131 104               9999999999          3                2013           20133 105               9999999999          2                2013           20132 106               9999999999          1                2013           20131 

suppose current month 4 , year 2013.

i need numbers table last entry . had tried query

select * tablename yearmonth=(select max(yearmonth) tablename) 

but problem numbers not appears last month number 999999999 has no value month 4 doesn't retrieve numbers.

how can last record of numbers.

select  *    (         select  *,                 row_number() on (partition mobilenumber order year desc, month desc, recordid desc) rn            mytable         ) q   rn = 1 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -