*row.id sorting backwards

I am having a problem with displaying a list of images and text from an SQLite query. I use the following syntax: 

local t = display.newText(text, 20, 30 * row.id, null, 16)

It works perfectly but, I am unable to sort the content so that it will display a list with the latest item on top.
I have tried sorting in the SQL query ORDER BY DESC, but it is not working. 

Also I have placed the results of the query in a Lua table and like this:

local t = table

for i = #t, 1, -1 do

var =  t[i]

end

When printing the var I get perfect backward sorting, but not when rendering the text elements with *row.id or *var   

What am I doing wrong? Any help is greatly appreciated. Thanks. 

Are you using “ORDER BY DESC” or “ORDER BY somefield DESC”?

Thank you for your reply. I have already found a workaround. The problem is that when using *row.id for rendering items for an SQL table, it doesn’t listen to WHERE clauses or sorting. Even if a row is empty, it will still be rendered, even the WHERE clause in the query excludes these results. This results in an empty space or an otherwise wrong result.

The solution I found is to everytime before rendering this list to copy all contents from the table to a new temporary SQL table, drop the old table, sort the contents, recreate the table and copy everything back. Afterwards drop the temporary table.

Its a bit cumbersome, but it works great now.

Are you using “ORDER BY DESC” or “ORDER BY somefield DESC”?

Thank you for your reply. I have already found a workaround. The problem is that when using *row.id for rendering items for an SQL table, it doesn’t listen to WHERE clauses or sorting. Even if a row is empty, it will still be rendered, even the WHERE clause in the query excludes these results. This results in an empty space or an otherwise wrong result.

The solution I found is to everytime before rendering this list to copy all contents from the table to a new temporary SQL table, drop the old table, sort the contents, recreate the table and copy everything back. Afterwards drop the temporary table.

Its a bit cumbersome, but it works great now.