简体   繁体   中英

How to combine two queries in to the one line query

I want to using the first query result to apply on the second query. Then I got some problems.

(My environment is Node.js , but it doesn't cause the influence of this question.)


FIRST QUERY

SELECT (TO_SECONDS('2015-02-10 23:00:00') - TO_SECONDS(NOW())) AS remainSeconds

then I will get the numeric result 'remainSeconds' like '-1957'.

If 'remainSeconds' > 0 will run the second query.

SECOND QUERY

// '...' is not important, so I skip them.

INSERT INTO tableA(...) SELECT ... FROM tableB

My problem summary :

We know there is some delay between the two queries running. And this delay time will cause some critical problems in some cases.

How to combine above two queries in to the one line query.

Just add the (TO_SECONDS('2015-02-10 23:00:00') - TO_SECONDS(NOW())) in the where of your SELECT

eg

INSERT INTO tableA(...) SELECT ... FROM tableB WHERE (TO_SECONDS('2015-02-10 23:00:00') - TO_SECONDS(NOW())) > 0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM