Question

I have two Queries which are related to two identical tables (Column names and everything is same)

Query1: "SELECT * FROM Notifications ORDER BY SUBSTR(DATE('NOW'), 0)>SUBSTR(DateToNotify, 0), SUBSTR(DateToNotify, 0)";

Query2: "SELECT * FROM NotificationsCron ORDER BY SUBSTR(DATE('NOW'), 0)>SUBSTR(DateToNotify, 0), SUBSTR(DateToNotify, 0)";

How to merge the results into one single cursor? I would want to have a join instead of merge cursor.

Was it helpful?

Solution

You should select from the UNION of both tables. Note if you use UNION instead of UNION ALL then duplicate records will be deleted from the result set)

SELECT * FROM 
   (SELECT * FROM Notifications 
    UNION ALL
    SELECT * FROM NotificationsCron
    ) T
ORDER BY SUBSTR(DATE('NOW'), 0)>SUBSTR(DateToNotify, 0), SUBSTR(DateToNotify, 0)

OTHER TIPS

Use the UNION clause:

Query = "SELECT * FROM (SELECT * FROM Notifications UNION SELECT * FROM NotificationsCron) T ORDER BY SUBSTR(DATE('NOW'), 0)>SUBSTR(DateToNotify, 0), SUBSTR(DateToNotify, 0)";

Note that the two tables MUST have the same columns - If not, then create fake columns inside the queries themselves by using aliases.

For reference: http://www.tutorialspoint.com/sqlite/sqlite_unions_clause.htm

you can use UNION ALL Clause

exp:

SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]

UNION ALL

SELECT column1 [, column2 ]
FROM table1 [, table2 ]
[WHERE condition]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top