0

The sample code that I am referring to is as follows:

SELECT top(3) * FROM AcceptorRequests
WHERE Terminal IN ('70270191','70347395')
ORDER BY Id DESC

But it works for only one terminal number. I want to display three end records for each terminal.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Younes Koopai
  • 51
  • 1
  • 11

2 Answers2

0
;with cte
as
(
SELECT  *,row_number() over (partition by terminal order by id desc) as rownum  FROM AcceptorRequests 
WHERE Terminal IN ('70270191','70347395')
)
select * from cte where rownum<=3
TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
-1

You could use union all :

SELECT top(3) * 
FROM AcceptorRequests 
WHERE Terminal = '70270191'
UNION ALL
SELECT top(3) * 
FROM AcceptorRequests 
WHERE Terminal = '70347395'
order by Id desc
SelVazi
  • 10,028
  • 2
  • 13
  • 29