简体   繁体   English

使用条款在第二张表中插入

[英]INSERT INTO SECOND TABLE USING WHERE CLAUSE

'Routes' table includes same route upto 6 times, only want to keep record with latest 'File date' & copy these into 'Routes2' table “路线”表最多可包含6条相同的路线,只希望保留最新的“文件日期”记录并将其复制到“路线2”表中

Heidi SQL 海蒂SQL

TRUNCATE TABLE temp.Routes2 
INSERT INTO temp.Routes2 
SELECT * 
from temp.Routes 
where temp.`File Date` = select max(t2.`File Date`) from temp.Routes as t2
LIMIT 100

get SQL error 1064 出现SQL错误1064

Sure, I just miss understood the syntax 当然,我只是想念语法

Many Thanks Simon 非常感谢西蒙

You want parenthesis & reference from outerquery to make it correlated subquery : 您希望括号和来自externalquery的引用使其与子查询相关:

SELECT t.*
FROM temp.Routes as t1
WHERE temp.`File Date` = (select max(t2.`File Date`) 
                          from temp.Routes as t2
                          where t1.col = t2.col
                         );

Try below - 尝试以下-

    INSERT INTO temp.Routes2 
    SELECT * 
    from temp.Routes a
    where a.`File Date` = (select max(t2.`File Date`) from temp.Routes as t2)
    order by temp.`File Date` limit 100

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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