SQL Challenge
Phil Scarratt <[email protected]>
| Newsgroups | gmane.org.user-groups.slug.chat,gmane.org.user-groups.slug.coders |
|---|---|
| Message-ID | <[email protected]> |
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 -- SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html