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 |
|
hawkpie
Starting Member
3 Posts |
Posted - 2005-09-29 : 04:17:55
|
| Sorry if this is an easy one, but it just has me stumped.I have a table with 2 columns, here's a quick snapshot of the data:applicantid skillid387 1387 2387 5387 7388 1388 2388 3388 5388 7I need to write a Select statement that selects all applicant ids for, say, skillids 1 and 3. But they must have them BOTH.Can't use IN and OR, as this selects people who have at least one of them.Any pointers would be appreciated.Cheerspie |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2005-09-29 : 04:23:28
|
| There's various ways of doing this, one of them might beSELECT applicantid FROM yourtable WHERE skillid = 1 AND applicantid IN (SELECT applicantid FROM yourtable WHERE skillid = 3)-------Moo. :) |
 |
|
|
hawkpie
Starting Member
3 Posts |
Posted - 2005-09-29 : 04:36:55
|
| Cheers MooThat would work great for 2 Ids, but forgot to mention that there could be none, 1 or up to 8.The skills requried are chosen by the user, depending on what they are after.tapie |
 |
|
|
iminore
Posting Yak Master
141 Posts |
Posted - 2005-09-29 : 04:46:35
|
| You could use a temporary table. First create a temporary table of all users matching your first skill id. Then delete from the temprary table those that don't meet successive skill ids. Finally read the temporary table for your results. |
 |
|
|
byrmol
Shed Building SQL Farmer
1591 Posts |
|
|
hawkpie
Starting Member
3 Posts |
Posted - 2005-09-29 : 05:04:10
|
| hi guyscheers for the replies. i got the answer on another forum and here it is if you are interested.select applicantidfrom myTablewhere skillid in (1, 3)group by applicantidhaving count(skillid) = 2cheers againpie |
 |
|
|
|
|
|