2011/6/25 Cecil Westerhof <cldwester...@gmail.com>

> With LIMIT you can get the first N records of a SELECT. Is it also possible
> to get the last N records?
>

Thanks for the answers. I had thought about both options, but was wondering
if I had missed something better. I original opted for the LIMIT/OFFSET
option (because the order is important), but after following the link I
found that this will be an ineffective way in the long run. That is way I
choose the DESC way in combination with tac. (I am using a bash script.):
    selectStr="
    SELECT   categories.desc
    ,        weights.measureDate
    ,        weights.weight
    ,        weights.fat
    ,        weights.water
    ,        weights.muscle
    FROM     weights
    ,        categories
    WHERE    categories.desc = 'Cecil'
         AND weights.categoryID = categories.id
    ORDER BY weights.measureDate DESC
    LIMIT    ${SHOW_NUMBER}
    ;
    "
    for record in $(echo "${selectStr}" | sqlite3 ${DATABASE} | tac) ; do

-- 
Cecil Westerhof
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to