首页 > 数据库 >【SQL Server】 两张相同字段的表拼接(Union)

【SQL Server】 两张相同字段的表拼接(Union)

时间:2022-09-22 19:34:40浏览次数:40  
标签:CODE Union times1 t2 t1 SQL date Server times

SELECT date,name,code,times,times1 FROM ((
        SELECT
            t1.date,
            t1.NAME,
            t1.CODE,
            t1.times,
            t2.times1 
        FROM
            table1 t1
            LEFT JOIN table2 t2 ON t1.CODE = t2.CODE
UNION
        SELECT
            t2.date,
            t2.NAME,
            t2.CODE,
            t1.times,
            t2.times1 
        FROM
            table1 t1
            RIGHT JOIN table2 t2 ON t1.CODE = t2.CODE 
        WHERE
            t1.CODE IS NULL
)) AS temp ORDER BY date

 

标签:CODE,Union,times1,t2,t1,SQL,date,Server,times
From: https://www.cnblogs.com/luyj00436/p/16720619.html

相关文章