C/C++教程

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

本文主要是介绍SQL语句将两个select语句查询结果合并一个,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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
3      
4  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
5  from (SELECT TOP 1 * FROM T_CONNSTATUSLOG WHERE PROBERID='TELC01' ORDER BY ID DESC) A 
6  FULL JOIN (SELECT TOP 1 * FROM T_PRODUCTLOG WHERE PROBERID='TELC01' ORDER BY ID DESC) b on a.PROBERID=b.PROBERID

 

这篇关于SQL语句将两个select语句查询结果合并一个的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!