Author |
Topic |
iissa69
Starting Member
5 Posts |
Posted - 2005-01-18 : 09:24:38
|
I am struggling with a query and need urgent help.I have a table with fieldscanidskillLevelpercentdateand example of the results wud becanid skillLevel Percent Date704 1 20 n/a705 2 10 n/a775 1 50 n/awhat i want to do is produce a query that would return a result from the following search criterareturn all results that matchskilllevel 1 and 20 percent AND skillLevel 2 and 10 percentI tried this below but obviously im doing something wrongselect * from simulatedHistory where((skilllevel = 1 and percent = 20) And (skilllevel = 2 and percent = 10))I need the query returning canid skillLevel Percent Date704 1 20 n/a705 2 10 n/aany suggestions??? any help wud be much appreciated |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-18 : 09:35:36
|
use union?select t.* from(select * from simulatedHistory whereskilllevel = 1 and percent = 20union allselect * from simulatedHistory whereskilllevel = 2 and percent = 10) tGo with the flow & have fun! Else fight the flow |
|
|
iissa69
Starting Member
5 Posts |
Posted - 2005-01-18 : 09:49:21
|
that kinda worked, but if it matches one of the two select statements, it returns a row.... but i want it to only return when it matches both of the statements!:D |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-18 : 09:50:59
|
then i believe you just need to change the and to or:select * from simulatedHistory where((skilllevel = 1 and percent = 20) OR (skilllevel = 2 and percent = 10))Go with the flow & have fun! Else fight the flow |
|
|
iissa69
Starting Member
5 Posts |
Posted - 2005-01-18 : 09:55:19
|
i tried that before posting the topic, but this kinda does a similar job to the union, if it matches one lot of statement, then it will return the result, and if it matches the other statment it will return the other lot of results..... i need it to match both sets of statements for a result to return! |
|
|
tuenty
Constraint Violating Yak Guru
278 Posts |
Posted - 2005-01-18 : 10:14:59
|
quote: Originally posted by iissa69...select * from simulatedHistory where((skilllevel = 1 and percent = 20) And (skilllevel = 2 and percent = 10))...
this should work just fineselect * from simulatedHistory where(skilllevel = 1 and percent = 20) or(skilllevel = 2 and percent = 10) can you post the ddl of the table?.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.*.A candle loses nothing by lighting another candle |
|
|
iissa69
Starting Member
5 Posts |
Posted - 2005-01-18 : 10:36:52
|
this is the same reply as spirit1, but i need it to match that two lot of statements, not just one or the other!!! it has to match both statments, and then return the result! |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-19 : 03:07:07
|
will this work for you then?declare @simulatedHistory table(canid int, skillLevel int, [Percent] int)insert into @simulatedHistoryselect 704, 1, 20 union allselect 705, 2, 10 union allselect 775, 1, 50select * from @simulatedHistory where skilllevel in (1, 2) and [percent] in (10, 20) Go with the flow & have fun! Else fight the flow |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2005-01-19 : 08:51:33
|
this should work for you -- you need to ensure that exactly 2 rows are returned for each CanID:select canID -- not * !from simulatedHistory where(skilllevel = 1 and percent = 20) or (skilllevel = 2 and percent = 10)group by CanIDhaving count(*)=2 - Jeff |
|
|
iissa69
Starting Member
5 Posts |
Posted - 2005-01-21 : 04:11:41
|
works a treat! thanks for all your help people!Much Appreciated |
|
|
|