Subject | SQL query question (IN limitation) |
---|---|
Author | nikicab_1999 |
Post date | 2006-05-03T15:58:27Z |
Hi all,
this is killing me. Since the IN clause has a limit, I have to find a
way around it.
Here are my tables and what I need to acomplish:
Setting_Defs table:
Setting_id INT
,Setting_Title VARCHAr(255)
Setting_Vals table
User_id INT
,Setting_id INT
,Setting_Value FLOAT
User checks list (checkbox list) in a GUI to pick list of
Setting_id(s) from Defs table in order to search by them.
user can use AND or OR. I have to bring all setting from the Vals
table that meet criteria. Let's suppose user picked Settings 125 and
159 and wants to find all settings for all User_id that have both (125
and 159) satisfying search criteria:
SELECT User_id FROM Setting_Vals WHERE
(Setting_id = 125 and Setting_Value BETWEEN 280 and 295)
AND (Setting_id = 159 and Setting_Value BETWEEN 0.5 and 3.8)
Problem is that this returns nothing even if there is the same User_id
having both settings in the ranges.
If I go to OR than it returns to much.
I did
SELECT DISTINCT User_id FROM Setting_Vals
WHERE User_id IN(SELECT User_id from Setting_Vals WHERE (Setting_id =
125 and Setting_Value BETWEEN 280 and 295))
AND User_id IN(SELECT User_id WhERE (Setting_id = 159 and
Setting_Value BETWEEN 0.5 and 3.8))
and it works but the problem is limitation of the IN (1499)
Any other, more elegant way to acomplish this?
Thanks,
Nik
this is killing me. Since the IN clause has a limit, I have to find a
way around it.
Here are my tables and what I need to acomplish:
Setting_Defs table:
Setting_id INT
,Setting_Title VARCHAr(255)
Setting_Vals table
User_id INT
,Setting_id INT
,Setting_Value FLOAT
User checks list (checkbox list) in a GUI to pick list of
Setting_id(s) from Defs table in order to search by them.
user can use AND or OR. I have to bring all setting from the Vals
table that meet criteria. Let's suppose user picked Settings 125 and
159 and wants to find all settings for all User_id that have both (125
and 159) satisfying search criteria:
SELECT User_id FROM Setting_Vals WHERE
(Setting_id = 125 and Setting_Value BETWEEN 280 and 295)
AND (Setting_id = 159 and Setting_Value BETWEEN 0.5 and 3.8)
Problem is that this returns nothing even if there is the same User_id
having both settings in the ranges.
If I go to OR than it returns to much.
I did
SELECT DISTINCT User_id FROM Setting_Vals
WHERE User_id IN(SELECT User_id from Setting_Vals WHERE (Setting_id =
125 and Setting_Value BETWEEN 280 and 295))
AND User_id IN(SELECT User_id WhERE (Setting_id = 159 and
Setting_Value BETWEEN 0.5 and 3.8))
and it works but the problem is limitation of the IN (1499)
Any other, more elegant way to acomplish this?
Thanks,
Nik