I have this SQL query that works perfect:
<code>SELECT * FROM VEHICLE_TEST WHERE Model REGEXP '[[:<:]]F150[[:>:]]' AND `Type` = 'Truck';
<code>SELECT * FROM VEHICLE_TEST WHERE Model REGEXP '[[:<:]]F150[[:>:]]' AND `Type` = 'Truck';
</code>
SELECT * FROM VEHICLE_TEST WHERE Model REGEXP '[[:<:]]F150[[:>:]]' AND `Type` = 'Truck';
I am trying to create a store procedure for this to pass in model from a node backend but having issues..
CREATE DEFINER=`reports`@`localhost` PROCEDURE `get_types`(IN `model` VARCHAR(20))
SELECT * FROM VEHICLE_TEST WHERE Model REGEXP CONCAT('[[:<:]]', model, '[[:>:]]') AND `Type` = 'Truck';
<code>DELIMITER $$
CREATE DEFINER=`reports`@`localhost` PROCEDURE `get_types`(IN `model` VARCHAR(20))
BEGIN
SELECT * FROM VEHICLE_TEST WHERE Model REGEXP CONCAT('[[:<:]]', model, '[[:>:]]') AND `Type` = 'Truck';
END$$
DELIMITER ;
</code>
DELIMITER $$
CREATE DEFINER=`reports`@`localhost` PROCEDURE `get_types`(IN `model` VARCHAR(20))
BEGIN
SELECT * FROM VEHICLE_TEST WHERE Model REGEXP CONCAT('[[:<:]]', model, '[[:>:]]') AND `Type` = 'Truck';
END$$
DELIMITER ;
This causes mysql to hang for a bit and then return too much data where is I just run the first query above, it brings back the correct amount of data and is very fast.
Each row in my table has a model field with data like this:
<code>100 | 150 | F150 | F150-235 | 50 | 58 | 60 | 65 | 70 | 76 | 77 | 95 | 99 | 100 | 111 | 120 | 140 | 150 | 152 | 170 | 172 | 175 | 177 | 180 | 182 | 185 | 188 | 190 | 195 | 200 | 206 | 207 | 208 | 210 | 300 | 314 | 320 | 321 | 335 | 336 | 337 | 340 | 382 | 390 | 400 | 401 | 402 | 404 | 406 | 408 | 411 | 414 | F150 (King Cab) | 425 | 441 | 500 | 501 | 510 | 525 | 550 | 551 | 552 | 560 | 650 | 680 | 700 | F150235 | 1900 | 2000 | 4000 | 1049-54 | 1049C-55 | 1049D-55 | 1049E-55 | 150F-55 | F150-82 | 1049G-82 | F150 (King Ranch) | 1329-23E
<code>100 | 150 | F150 | F150-235 | 50 | 58 | 60 | 65 | 70 | 76 | 77 | 95 | 99 | 100 | 111 | 120 | 140 | 150 | 152 | 170 | 172 | 175 | 177 | 180 | 182 | 185 | 188 | 190 | 195 | 200 | 206 | 207 | 208 | 210 | 300 | 314 | 320 | 321 | 335 | 336 | 337 | 340 | 382 | 390 | 400 | 401 | 402 | 404 | 406 | 408 | 411 | 414 | F150 (King Cab) | 425 | 441 | 500 | 501 | 510 | 525 | 550 | 551 | 552 | 560 | 650 | 680 | 700 | F150235 | 1900 | 2000 | 4000 | 1049-54 | 1049C-55 | 1049D-55 | 1049E-55 | 150F-55 | F150-82 | 1049G-82 | F150 (King Ranch) | 1329-23E
</code>
100 | 150 | F150 | F150-235 | 50 | 58 | 60 | 65 | 70 | 76 | 77 | 95 | 99 | 100 | 111 | 120 | 140 | 150 | 152 | 170 | 172 | 175 | 177 | 180 | 182 | 185 | 188 | 190 | 195 | 200 | 206 | 207 | 208 | 210 | 300 | 314 | 320 | 321 | 335 | 336 | 337 | 340 | 382 | 390 | 400 | 401 | 402 | 404 | 406 | 408 | 411 | 414 | F150 (King Cab) | 425 | 441 | 500 | 501 | 510 | 525 | 550 | 551 | 552 | 560 | 650 | 680 | 700 | F150235 | 1900 | 2000 | 4000 | 1049-54 | 1049C-55 | 1049D-55 | 1049E-55 | 150F-55 | F150-82 | 1049G-82 | F150 (King Ranch) | 1329-23E
My query searches these fields for every row looking for whole words ‘F150″ and will match on “F150”, “F150 (King Cab)” and “F150 (King Ranch)” but not on one’s like F150-82 and F150-235 as that isn’t a whole word match.
Any ideas what I am doing wrong?