StoyanGrigorov

Untitled

Feb 11th, 2017
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.38 KB | None | 0 0
  1. DECLARE @LastChatId INT = (SELECT TOP (1) c.Id FROM Chats AS c
  2.                             ORDER BY c.StartDate DESC)
  3.  
  4. DECLARE @FirstMessage VARCHAR(200) =
  5.                                     (
  6.                                         SELECT TOP (1) m.Content
  7.                                         FROM Messages AS m
  8.                                         WHERE m.ChatId = @LastChatId
  9.                                         ORDER BY m.SentOn
  10.                                     )
  11.  
  12.  
  13. SELECT c.Title, @FirstMessage AS [Content]
  14. FROM Chats AS c
  15. WHERE c.Id = @LastChatId
Advertisement
Add Comment
Please, Sign In to add comment