Welcome Guest, Not a member yet? Register   Sign In
advanced myslq query
#2

[eluser]dudeami0[/eluser]
Havn't tested this query, but something like

case 1:
Code:
SELECT * FROM `tshirt` WHERE `colors` REGEXP '[^0-9]?1[^0-9]?' AND `colors` REGEXP '[^0-9]?3[^0-9]?'
case 2
Code:
SELECT * FROM `tshirt` WHERE `colors` REGEXP '[^0-9]?1[^0-9]?' AND `colors` REGEXP '[^0-9]?2[^0-9]?' AND `colors` REGEXP '[^0-9]?3[^0-9]?' AND `colors` REGEXP '[^0-9]?4[^0-9]?' AND `colors` REGEXP '[^0-9]?5[^0-9]?'
case 3
Code:
SELECT * FROM `tshirt` WHERE `colors` REGEXP '[^0-9]?4[^0-9]?' AND `colors` REGEXP '[^0-9]?5[^0-9]?'

That is just repeating the AND operative alot. You can do just one REGEXP check like:

case 1:
Code:
SELECT * FROM `tshirt` WHERE `colors` REGEXP '[^0-9]?1[^0-9]?.*[^0-9]?3[^0-9]?'
case 2:
Code:
SELECT * FROM `tshirt` WHERE `colors` REGEXP '[^0-9]?1[^0-9]?.*[^0-9]?2[^0-9]?.*[^0-9]?3[^0-9]?.*[^0-9]?4[^0-9]?.*[^0-9]?5[^0-9]?'
case 3:
Code:
SELECT * FROM `tshirt` WHERE `colors` REGEXP '[^0-9]?4[^0-9]?.*[^0-9]?5[^0-9]?'

That should work Big Grin

I didn't use LIKE because of the fact if you get into a 2+ digit number 20 could cause %2% to match it.

If you need help understanding how it works let me know. Also, there might be better solutions to this that I am not aware of.

EDIT: Updated the SQLs (Added the optional ? after the [^0-9]) and tested on my local MySQL server and it works fine!


Messages In This Thread
advanced myslq query - by El Forum - 11-04-2010, 02:05 AM
advanced myslq query - by El Forum - 11-04-2010, 02:18 AM
advanced myslq query - by El Forum - 11-04-2010, 02:56 AM
advanced myslq query - by El Forum - 11-04-2010, 06:45 AM
advanced myslq query - by El Forum - 11-04-2010, 06:21 PM
advanced myslq query - by El Forum - 11-04-2010, 07:11 PM
advanced myslq query - by El Forum - 11-07-2010, 01:28 AM
advanced myslq query - by El Forum - 11-07-2010, 03:03 AM



Theme © iAndrew 2016 - Forum software by © MyBB