Having a bit of an issue with this one. Is there a way to check if a value is in the range provided in a mysql query result.
How can I see if the Zip Code 85012 is within the ZipCodes field returned without first making a query, breaking it up into parts, and using BETWEEN?
+---------+-------------+--------------------+------------+-------------+
| StyleID | HistStyleID | AutobuilderStyleID | FilterRule | ZipCodes |
+---------+-------------+--------------------+------------+-------------+
| 355755 | 2013490103 | w2013k49m1t3 | includes | 27000-36999 |
+---------+-------------+--------------------+------------+-------------+
:: UPDATE ::
This table can also contain various ranges as follows..
+---------+-------------+--------------------+------------+-------------------------------------+
| StyleID | HistStyleID | AutobuilderStyleID | FilterRule | ZipCodes |
+---------+-------------+--------------------+------------+-------------------------------------+
| 332492 | 2012493107 | w2012k49m31t7 | excludes | 38600-39799,70000-71499,71600-79999 |
+---------+-------------+--------------------+------------+-------------------------------------+
Like it's been suggested in the comments, you should redesign your database:
CREATE TABLE Styles (
StyleID INT PRIMARY KEY,
HistStyleID INT,
AutobuilderStyleID VARCHAR(40),
FilterRule VARCHAR(40)
)
CREATE TABLE ZipCodes (
StyleID INT,
RangeBegin INT,
RangeEnd INT,
FOREIGN KEY StyleID REFERENCES Styles(StyleID)
)
Then you can make queries like:
SELECT DISTINCT StyleID FROM ZipCodes WHERE RangeBegin >= 85012 AND RangeEnd <= 85012