Hi folks. I do basic and some intermediate SQL querying a lot, but the solution to this query escapes me... i'm not sure how to accomplish this. Could someone lend a hand?
Let's say I have two tables, with the following columns:
grades_tbl: id, grade_lvl, grade_txt
programs_tbl: id, program_name, grade_from_id, grade_to_id
both ids, grade_lvl, grade_from_id, and grade_to_id are integers. grade_txt and program_nam are varchars.
grade_txt would be something like "Pre-K", "K", "1", "Adult", etc. grade_lvl is a number representation, to give the grades a hiearchy, so that Pre-K's grade_lvl might be "-2" and "K" might be "-1" and 1 would be "1", and so on... with "Adult" maybe being "13".
The task at hand is I receive a grade_id from a user. Say, it's grade_id=3. I look in the grades_tbl and find out what the grade_lvl and grade_txt are for that id. grade_id winds up being grade_lvl=3, grade_txt=3. Easy. Now, I need to query the programs_tbl and find programs whose grade_from is below the grade that the user selected, and whose grade_to is above it. This is where I get stuck.
Essentially, I need to query grades_tbl to find out what grade_from_id's grade_txt and grade_lvl are, and find out what grade_to_id's grade_txt and grade_lvl are. Then, I need to query programs_tbl to find out for which programs the user-selected grade falls in between grade_from and grade_to. It's tricky b/c programs_tbl doesnt have grade_tdxt and grade_lvl info, only the identifier grade_id. There's got to be a tight way to do this instead of a nest of ugly single CFQUERYs.
Can anyone offer some advice or a solution? Many thanks for your kindness!!
Jeff
Let's say I have two tables, with the following columns:
grades_tbl: id, grade_lvl, grade_txt
programs_tbl: id, program_name, grade_from_id, grade_to_id
both ids, grade_lvl, grade_from_id, and grade_to_id are integers. grade_txt and program_nam are varchars.
grade_txt would be something like "Pre-K", "K", "1", "Adult", etc. grade_lvl is a number representation, to give the grades a hiearchy, so that Pre-K's grade_lvl might be "-2" and "K" might be "-1" and 1 would be "1", and so on... with "Adult" maybe being "13".
The task at hand is I receive a grade_id from a user. Say, it's grade_id=3. I look in the grades_tbl and find out what the grade_lvl and grade_txt are for that id. grade_id winds up being grade_lvl=3, grade_txt=3. Easy. Now, I need to query the programs_tbl and find programs whose grade_from is below the grade that the user selected, and whose grade_to is above it. This is where I get stuck.
Essentially, I need to query grades_tbl to find out what grade_from_id's grade_txt and grade_lvl are, and find out what grade_to_id's grade_txt and grade_lvl are. Then, I need to query programs_tbl to find out for which programs the user-selected grade falls in between grade_from and grade_to. It's tricky b/c programs_tbl doesnt have grade_tdxt and grade_lvl info, only the identifier grade_id. There's got to be a tight way to do this instead of a nest of ugly single CFQUERYs.
Can anyone offer some advice or a solution? Many thanks for your kindness!!
Jeff