Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
joshymraj
Starting Member
5 Posts |
Posted - 2007-02-21 : 02:23:13
|
| Hello guys i got a problem when i tried to retrieve a value that has multiple match with different rows.I got a table with fields plan_id and feature_no,of which plan_id are numbers(1,2,3...) and feature_no are also nums(1,2,3...).For each plan id there are multiple features.Looks likeplan_id feature_id1 21 41 61 82 42 53 43 63 8I want to retrieve plan_id which includes selected features.For eg.i want plan_ids with features 4,6,8 so it should return plan_ids 1 and 3.Is there any solution for this.Plz help me guysjoshymraj |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-21 : 02:49:03
|
| [code]-- prepare sample datadeclare @s table (plan_id int, feature_id int)insert @sselect 1, 2 union allselect 1, 4 union allselect 1, 6 union allselect 1, 8 union allselect 2, 4 union allselect 2, 5 union allselect 3, 4 union allselect 3, 6 union allselect 3, 8-- Show the expected outputSELECT Plan_IDFROM @sWHERE Feature_ID IN (4, 6, 8)GROUP BY Plan_IDHAVING COUNT(DISTINCT Feature_ID) = 3[/code]Peter LarssonHelsingborg, Sweden |
 |
|
|
joshymraj
Starting Member
5 Posts |
Posted - 2007-02-21 : 03:10:22
|
| Thank you very much Peso.It worked !I am very very happy now coz i m in the middle of a web project and was thinking to change the design coz of this problem.This query exactly suits my use.joshymraj |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-21 : 03:46:23
|
| Good luck!Peter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|