Please see sample code
-- 1st select, getting AssetID from asset table
SELECT GROUP_CONCAT(AssetID)
INTO @AssetIDs
FROM asset;
-- 2nd select, use @AssetIDs in an IN clause
SELECT AssetID
from asset
where AssetID IN (@AssetIDs)
From the 1st select, it returns 10 IDs and those IDs get stored in @AssetIDs
So i would imagine @AssetIDs = '1,2,3,4,5,6,7,8,9,10'
However, the second select always return the first ID, 1.
Can anyone help me find a way to select the list of IDs in a variable that reuse that variable in the IN clause?
in (select AssetID from asset)- If you reall have to do it see stackoverflow.com/questions/21101211/mysql-variable-in-clauseselect AssetID from assetas the simplest query anyway with noINwhere AssetID IN ('1,2,3,4,5,6,7,8,9,10'), MySQL implicitely converts your string '1,2,3,4,5,6,7,8,9,10' to int which it does by simply taking all digits from left, which is '1' only. So the query finds the record with ID 1. I don't like this conversion very much, I'd rather see it resulting in an error, because '1,2,3,4,5,6,7,8,9,10' obviously isn't an integer. But well, this is how the MySQL guys decided to do it.