samedi 30 avril 2016

How to select data from a database, sort it and insert it in another database in SQLite android?

I have a table which contains values from 2 tree map. I couldn't merge them into one and pass as a single map because the input contains duplicates . In short, the data in my table looks like

APPLE  1
BANANA 4
ORANGE 5
GRAPES 1
POTATO 9

I want to sort the integers in ascending order. I tried using order by clause in select statement and used that select statement for creating another table in sorted manner but I couldn't do as there is some missing parenthesis in exec statement.

db.execSQL(INSERT INTO my_ordered_table (name, num) SELECT name,num FROM my_table ORDER BY name ;

I tried writing this but I don't know where to insert parenthesis, " " etc . The column values are dynamic ones and not hard coded values .

I even want INSERT IF EXISTS ELSE UPDATE condition in the insert statement.Any help would be great !! Thanks

Aucun commentaire:

Enregistrer un commentaire