11,573,084 members (64,716 online)
Rate this:
See more:
Hi,
I have a table which has 2 columns namely PlanId and RiderId in below format-
Query is- I want pass multiple riderid and i want to get `PlanId` on the base of multiple `RiderId`.
In this case i will pass `327,329,330,326,355`.
But 327 available in 2 times in `PlanId` column having `356349` and `356347 `but here i want only one `PlanId` which is `356349` , because it hold combination values. How i accomplish this.

```PlanId	RiderId
===============
356348	330
356348	355
356348	327
356348	329
356349	327
356349	329
356349	330
356349	326
356349	355```
Posted 7-Feb-13 3:16am
Edited 10-Feb-13 23:58pm
Maciej Los186.5K
v2
skydger at 7-Feb-13 9:48am

What query do you use?
Sheikh Muhammad Haris at 7-Feb-13 14:04pm

What is you Combination Value logic? Why do you want to select 356349 ?

Rate this:

## Solution 1

Hi,

I think you want to use GROUPS, let's see if I understand:

```SELECT
YourTable.PlanId
,YourTable.RiderId
FROM
YourTable
GROUP BY
YourTable.PlanId,
YourTable.RiderId
HAVING
--Example:
--YourTable.RiderId IN (327,329,330,326,355)
```

Hope it helps
v2
Rate this:

## Solution 2

Write stored procedure[^], like this:
```CREATE PROCEDURE GetPlanIDByRiderID
@riderids NVARCHAR(1000)
--example input: '321, 322, 333'
AS

SELECT PlanId, RiderId
FROM YourTable
WHERE RiderId IN (@riderids)
ORDER BY PlanId, RiderId

GO```