I have the following scenario:
The user will input an interval and/or single comma-separated number codes for each product.
Partial table example:
name | codes
-----------------------------------
Product 1 | 239,300-350
Product 2 | 430-450,500,29
Product 3 | 780,2
For example, when the user searches for code 321, it should return the row of Product 1.
Is there a way for doing that search with a single query?
I’d suggest doing this with two tables instead:
Then you can get what you want (for some
$input_id) by using a join:You can have multiple rows in the
code_rangestable for each product to represent multiple different ranges (e.g.2-4,7-10would have two rows, one withrange_start=2andrange_end=4, and another for the 7-10 range).A product code that isn’t a range would simply be treated as a range where the start and end are the same (e.g.
7would berange_start=7andrange_end=7).