MySQL error with IN output and parameter

I find it difficult with a query in MySQL.

I am working with Delphi XE and I am sending a request with some parameter to MySQL. Here is an example request:

SELECT * FROM users u WHERE u.id IN (:idUsers);

": idUsers" is a variable that will receive a parameter that I send using Delphi, which is a string that is formatted as follows, for example: 1,2,3

The problem is that with this line I get only the first user (id = 1). From what I see, it, just like MySQL, adds some quote ('') at the beginning and at the end of the line that I am sending, for example, if it was “1,2,3” instead of 1,2, 3. I tried this choice:

SELECT * FROM users u WHERE u.id IN ('1,2,3'); 

and it really only returns the first user.

I had a function in MSSQL that split the row I placed and returned a temporary table, but we recently switched to MySQL, and from what I read, MySQL does not allow the table to be returned.

Does anyone know how to solve this problem? I refuse the Internet for an answer and have not found it for this particular problem.

Thanks for the help.

+5
source share
2 answers

; , , , , . ParamByName('WhatEver').AsString Value, , , , . , , , - IN ('1, 2, 3') IN (1, 2, 3).

, , WHERE . (, , IN, , .)

+10

IN, MYSQL ( ID), - :

SELECT * FROM users u WHERE u.id IN (SELECT ID FROM TEMPTABLE); 

TEMPTABLE , , .

. . , .

0

All Articles