I have code like this.
DELIMITER $$
CREATE PROCEDURE `sp_deleteOrderData`(orderid BIGINT(11))
BEGIN
DECLARE shipmentnumbers VARCHAR(1000);
FIND_IN_SET
searches a string inside a set of string separated by a comma.
But you don't need to use GROUP_CONCAT
to concatenate the rows to be used in the IN
clause, try this,
SELECT GROUP_CONCAT(a_cartonid)
FROM t_carton
WHERE a_shipmentid IN
(
SELECT a_shipmentid
FROM t_shipment
WHERE a_orderid = orderid
)
or use JOIN
SELECT GROUP_CONCAT(DISTINCT a.a_cartonid)
FROM t_carton a
INNER JOIN
(
SELECT a_shipmentid
FROM t_shipment
WHERE a_orderid = orderid
) b ON a.a_shipmentid = b.a_shipmentid
IN
accepts a list or parameters to search, FIND_IN_SET
accepts a string parameter containing a comma-separated list:
SELECT 1 IN (1, 2, 3, 4)
SELECT FIND_IN_SET(1, '1,2,3,4')
If you try to apply IN
to a comma-separated string, it will treat it as a single parameter and will match it as a whole:
SELECT 1 IN ('1,2,3,4')
Of course, the string '1'
is not equal to the string '1,2,3,4'
so the query above returns false.