简体   繁体   中英

Simply MySQL SP Fetch Rows Based on CSV Returning Only 1 Row

I have a simply query to fetch products based on a comma separated list of IDs:

CREATE PROCEDURE `databaseName`.`fetchRecentlyViewed` (IN productIdCsv VARCHAR(128))
BEGIN
SELECT listingTitle, productName, productID FROM products WHERE productID IN (productIdCsv );
END

If I run this query against it:

CALL fetchRecentlyViewed ('6,7,4,3')

I only ever get the first product returned - its so simple I really don't know where to go from here!

I'm missing something obvious I'm sure!

So it seems that the most popular answer in the question relating to this also only returns one row: Pass array to MySQL stored routine

If you want to return more than one row, you need to use FIND_IN_SET

Here's a good resource on this:

FIND_IN_SET() vs IN()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM