문제

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.

도움이 되었습니까?

해결책

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)

다른 팁

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]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top