![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have table I which when has G, F, L I can query to get a list: select L, U from I where G='111'; This gives me a list in ascending order like: L U ---- ---- 1000 1049 2000 2010 etc. I can now manually loop (outside of MySql) over the list from table I and build a query on table II such that after putting in these example values it evaluates to select V from II where V>=1000 and V<=1049 UNION ALL select V from II where V>=2000 and V<=2010 etc. this is the query for the list of all the permitted values of V. What I would _really_ like to do is build a single query such that it pulls each of the lower and upper bounds from table I and puts them in properly. That means that supposing table II has the following values for V: 1023, 1037, 1075, 2007 that the query fragment above would return 1023, 1037, 2007. IOW, the value 1075 is not within proper bounds of upper and lower so it is omitted. Any ideas? -- Shelly |
#3
| |||
| |||
|
|
I have table I which when has G, F, L I can query to get a list: select L, U from I where G='111'; This gives me a list in ascending order like: L U ---- ---- 1000 1049 2000 2010 etc. |
|
I can now manually loop (outside of MySql) over the list from table I and build a query on table II such that after putting in these example values it evaluates to select V from II where V>=1000 and V<=1049 UNION ALL select V from II where V>=2000 and V<=2010 etc. |
#4
| |||
| |||
|
|
On 8月13日, 上午3时22分, sheldonlg<sheldo... (AT) thevillages (DOT) net> wrote: I have table I which when has G, F, L I can query to get a list: select L, U from I where G='111'; This gives me a list in ascending order like: L U ---- ---- 1000 1049 2000 2010 etc. I can now manually loop (outside of MySql) over the list from table I and build a query on table II such that after putting in these example values it evaluates to select V from II where V>=1000 and V<=1049 UNION ALL select V from II where V>=2000 and V<=2010 etc. this is the query for the list of all the permitted values of V. What I would _really_ like to do is build a single query such that it pulls each of the lower and upper bounds from table I and puts them in properly. That means that supposing table II has the following values for V: 1023, 1037, 1075, 2007 that the query fragment above would return 1023, 1037, 2007. IOW, the value 1075 is not within proper bounds of upper and lower so it is omitted. Any ideas? -- Shelly select V from II where (v>=1000 and v<=1049) or (V>=2000 and v<=2010) I'am sorry I can't test and verify ,may be it can solve |
#5
| |||
| |||
|
|
I have table I which when has G, F, L I can query to get a list: select L, U from I where G='111'; This gives me a list in ascending order like: L U ---- ---- 1000 1049 2000 2010 etc. I can now manually loop (outside of MySql) over the list from table I and build a query on table II such that after putting in these example values it evaluates to select V from II where V>=1000 and V<=1049 UNION ALL select V from II where V>=2000 and V<=2010 etc. this is the query for the list of all the permitted values of V. What I would _really_ like to do is build a single query such that it pulls each of the lower and upper bounds from table I and puts them in properly. That means that supposing table II has the following values for V: 1023, 1037, 1075, 2007 that the query fragment above would return 1023, 1037, 2007. IOW, the value 1075 is not within proper bounds of upper and lower so it is omitted. Any ideas? |
#6
| |||
| |||
|
|
"sheldonlg" <sheldonlg (AT) thevillages (DOT) net> wrote in message news:j23ut5$po5$1 (AT) dont-email (DOT) me... I have table I which when has G, F, L I can query to get a list: select L, U from I where G='111'; This gives me a list in ascending order like: L U ---- ---- 1000 1049 2000 2010 etc. I can now manually loop (outside of MySql) over the list from table I and build a query on table II such that after putting in these example values it evaluates to select V from II where V>=1000 and V<=1049 UNION ALL select V from II where V>=2000 and V<=2010 etc. this is the query for the list of all the permitted values of V. What I would _really_ like to do is build a single query such that it pulls each of the lower and upper bounds from table I and puts them in properly. That means that supposing table II has the following values for V: 1023, 1037, 1075, 2007 that the query fragment above would return 1023, 1037, 2007. IOW, the value 1075 is not within proper bounds of upper and lower so it is omitted. Any ideas? If you will forgive the join style, then: select V from Table2, Table1 where G=111 and V >= L and V <= U I've substituted "Table1" for "I" and "Table2" for "II" as I think its slightly clearer. |
![]() |
| Thread Tools | |
| Display Modes | |
| |