Re: SQL Challenge
| Newsgroups | gmane.org.user-groups.slug.coders,gmane.org.user-groups.slug.chat |
|---|---|
| Message-ID | <1210091260.16162.8.camel@frank-laptop> |
Hi Phil I am not a SQL guru but the code below should do the trick I think: select F1, F2, F3 from T1 where F1 between minValue and maxValue and F2 between minValue and maxValue and F3 between minValue and maxValue Regards, Frank On Tue, 2008-05-06 at 22:51 +1000, Phil Scarratt wrote: > Hi SQL Gurus out there... > > After deliberation, searching, experimenting and so on, I think the > answer to my problem below is recursion in an sql procedure, but would > like feedback/comments before proceeding. My problem with recursion is > that it takes too long to be practical in this scenario - at least > recursion outside sql is (in this case php). Which leads me to the other > half of my question: is recursion in an sql procedure faster than > recursion in the host language? My assumption is yes, but how much or > what are peoples experience with this? > > The problem: I have a scenario where I have a table T1 with say 3 fields > F1, F2 and F3. From this table I need to select all rows whose F1 are in > a specific subset, as well as any rows from the matched rows so far > whose F2 fields are the same, as well as any rows from the matched rows > so far whose F3 fields are the same. Make sense? :) > > So, for example: > Table T1 > F1 F2 F3 > ---------- > 1 1 3 > 1 1 4 > 1 3 4 > 1 4 3 > 1 8 9 > 2 5 3 > 2 6 7 > > Given an input of say F1=1 and R1=1, how would one go about obtaining > the following result set: > F1 F2 F3 > ---------- > 1 1 3 > 1 1 4 > 1 3 4 > 1 4 3 > > Or with an input of say F1 in (1,2) and R1 in (1,5) > F1 F2 F3 > ---------- > 1 1 3 > 1 1 4 > 1 3 4 > 1 4 3 > 2 5 3 > > By the way, the database engine is MySQL v5. > > TIA and apologies for the cross-post and some people potentially getting > it twice. > Fil > > _______________________________________________ > coders mailing list > [email protected] > http://lists.slug.org.au/listinfo/coders