Skip to content
Advertisement

SQLite query for retrieve data Order By

(TableMain)
Task_Id  Task       DateTime          Repetition    Snooze_Time
8        Call esha  2020-3-15 12:29   1             5
9        Meeting    2020-3-15 11:50   1             1

(TableRoutine)
Task_Id  Task       DateTime          Repetition    Snooze_Time
1        Go to GYM  2020-3-15 14:18   0             0

I have two tables in SQLite

I need result like this in Order By DateTime: (Column DateTime in both table is data type of DateTime of SQLite) I’m using this query to merge two tables data. But I need data in below formate.

SELECT Task, DateTime FROM TableMain UNION ALL SELECT Task, DateTim FROM TableRoutine

But I need data in below formate.

Task        DateTime       
Meeting     2020-3-15 11:50 
Call esha   2020-3-15 12:29
Go to GYM   2020-3-15 14:18

Is it possible to retrieve data like this?

Advertisement

Answer

You even do not need a subquery:

SELECT Task, DateTime FROM TableMain 
UNION ALL 
SELECT Task, DateTime FROM TableRoutine
order by DateTime 

Demo

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement