I have an array of strings where id products are stored. How can I make a single query to the products table to get all the rows with the given id ?
1 answer
For such purposes, the predicate IN .
Example:
SELECT * FROM [dbo].[MyTable] mt WHERE mt.Id IN ('1','2','5') - oneWhy did the labels change the question? The author knowingly put the php label)) and in general it was necessary that he clarify it all. - Alexey Shimansky
- @ Alexey Shimansky, is there any php here?) - progmb
- I wrote about the question here I wrote that you would receive a notice - Alexey Shimansky
- @ Alexey Shimansky, I understood), but php, too, didn’t mention the same thing in the question - progmb
- 3yes, so it was worth, perhaps, to clarify something in the beginning, before changing the labels) - Alexey Shimansky
|
$sql = 'SELECT something FROM table WHERE id IN ('.implode(',', $idArray).')';- Alexey Shimansky