如何使用两个SQL表(SQL Server 2008)首先获取日志表数据



我需要一个SQL选择查询才能使用两个SQL Server表首先获取日志表数据,实际上我为什么使用日志表,因为当用户将更新他的文件时,它将存储在Table_AttachLog中,但是我友好地使用两个表之间的内部连接,因为它是记录表。我知道使用DESC使用updateddate列订单,我们可以获得如何使用两个表。

table_attachlog

RegistrationID     uploaded File             updateddate
---------------------------------------------------------------------
101                myprofile.doc             2018-03-25 00:45:08.500

table_registration

RegistrationID     Name      Email                 uploaded File         submitted
----------------------------------------------------------------------------
100                Rohan     rohan@gmail.com       rohanfile.doc       2018-01-12 00:45:08.500
101                mazhar    mazhar@gmail.com      myprofile.doc       2018-03-13 00:45:08.500
102                raj       raj@gmail.com         raj.doc             2018-01-16 00:45:08.500

我需要查询,即table_attachlog的更新日期应通过desc进行一阶,请访问以下

RegistrationID     Name      Email                 uploaded File         submitted
----------------------------------------------------------------------------
101                mazhar    mazhar@gmail.com      myprofile.doc       2018-03-13 00:45:08.500
100                Rohan     rohan@gmail.com       rohanfile.doc       2018-01-12 00:45:08.500
102                raj       raj@gmail.com         raj.doc             2018-01-16 00:45:08.500

左JOIN ISNULL应该这样做

select r.*
from Table_Registration r
left join Table_AttachLog a 
  on a.RegistrationID = r.RegistrationID  
order by isnull(a.updateddate, r.submitted) desc

最新更新