简体   繁体   中英

SELECT UPDATE ALL ROWS AT THE SAME TIME MYSQL

I'm trying to update and select the same table as the following:

UPDATE tbl_domain SET remain = 
(SELECT DATEDIFF(expdate,NOW()) FROM (
SELECT DATEDIFF(expdate,NOW()) FROM tbl_domain 
) as x )  

How can i make it work ? Someone please help me!!!

Try this:

UPDATE tbl_domain t, (SELECT DATEDIFF(expdate,NOW()) as remain
                        FROM tbl_domain 
                       ) t1
SET t.remain = t1.remain
-- WHERE t.Id = t1.Id --If you have some kind of unique id in your table.

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