I am stuck with FIND_IN_SET function in MYSQL 5.5, For example:
Please check below query, considering 10,9,5,8,21 are user id’s
SELECT u.user_id,u.first_name,u.last_name
FROM user u
WHERE
u.is_active = 'Y'
AND FIND_IN_SET(u.user_id,'10,9,5,8,21');
When I fire this query it give me results in Ascending order of user id’s that is in
5
8
9
10
21
I want in same order like I entered
10
9
5
8
21
Is there any way to achieve it?
STORED PROCEDURE
DROP PROCEDURE IF EXISTS databaseName.procName;
DELIMITER //
CREATE PROCEDURE databaseName.procName(IN ZoneIDs LONGTEXT)
BEGIN
SELECT u.user_id,u.first_name,u.last_name
FROM user u
WHERE u.is_active = 'Y'
AND FIND_IN_SET(u.user_id,ZoneIDs);
END //
DELIMITER ;
Try using it like this :
This uses
INto only select data whereu.useridis in that list and then orders by your specific order usingfind_in_setFIND_IN_SET returns the index of the first argument in the second argument – so I’m very surprised your query even worked …..