I have a 5 field table, and I want to make a qry like this:
SELECT *
FROM dbo.table
WHERE somefield in (90,120,30,90)
The problem is that I have several 90, 120 and 30 values in the rows of the table, but I want to return only first 4 rows, that match the criteria.
Is there any easy way to do this? I'm on SQL server 2008.
CREATE TABLE ForgeRock
([id] int, [somefield] int)
;
INSERT INTO ForgeRock
([id], [somefield])
VALUES
(1, 90),
(2, 90),
(3, 120),
(4, 30),
(5, 30),
(6, 90),
(7, 10),
(8, 20),
(9, 90),
(10, 30),
(11, 20)
;
Fidle with data and query.
Expected results would be 90,120,20,90
and their respected id
s.