how to use WHERE IN mysql stored procedure
You can use the string concatenation and the PREPARE statement to run dynamically built queries.
somestring
must be constructed in a valid SQL format like '1','2','3'
DELIMITER $$
DROP PROCEDURE IF EXISTS `abc`.`table1`$$
CREATE PROCEDURE `abc`.`test`
(IN somestring VARCHAR(255))
BEGIN
@s=CONCAT("
SELECT * FROM abc.table1
WHERE flight_type IN (",somestring,");")
PREPARE stmt FROM @s;
EXECUTE @s;
END $$
DELIMITER ;
You can use FIND_IN_SET()
if somestring
is formatted a,b,c,d
:
SELECT *
FROM abc.table1
WHERE FIND_IN_SET(flight_type, somestring)