1. SQL语句将两个select语句查询结果合并一个

用到”FULL JOIN”关键字语法

查询结果1:
SELECT TOP 1 * FROM T_CONNSTATUSLOG WHERE PROBERID=\'TELC01\' ORDER BY ID DESC
查询结果2:
SELECT TOP 1 * FROM T_PRODUCTLOG WHERE PROBERID=\'TELC01\' ORDER BY ID DESC
 
合并查询结果 
SELECT isnull(a.PROBERID,b.PROBERID) PROBERID, ISNULL(a.ID,0) aID,ISNULL(a.INSERTTIME,0) INSERTTIME,isnull(a.CONNSTATUS,0) CONNSTATUS,ISNULL(b.ID,0) bID ,isnull(b.PROBERCARDID,0) PROBERCARDID,isnull(b.READTIME,0) READTIME
from (SELECT TOP 1 * FROM T_CONNSTATUSLOG WHERE PROBERID=\'TELC01\' ORDER BY ID DESC) a 
FULL JOIN (SELECT TOP 1 * FROM T_PRODUCTLOG WHERE PROBERID=\'TELC01\' ORDER BY ID DESC) b on a.PROBERID=b.PROBERID

 

版权声明:本文为RookieJ原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/RookieJ/p/14537604.html