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 ?

  • five
    $sql = 'SELECT something FROM table WHERE id IN ('.implode(',', $idArray).')'; - Alexey Shimansky

1 answer 1

For such purposes, the predicate IN .

Example:

 SELECT * FROM [dbo].[MyTable] mt WHERE mt.Id IN ('1','2','5') 
  • one
    Why 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
  • 3
    yes, so it was worth, perhaps, to clarify something in the beginning, before changing the labels) - Alexey Shimansky