Checking value in an array inside one SQL query with WHERE clause

前端 未结 4 622
萌比男神i
萌比男神i 2021-01-04 03:22

I want to know is this practically possible in sql(using php as server-side), where in you have an array of values(numbers), and you try to retrieve data based on values ins

4条回答
  •  借酒劲吻你
    2021-01-04 04:10

    Yes, this is easily possible. You need to look at MySQL's IN function

    Your query would be something like

    SELECT * FROM posts WHERE user_id IN (1,2,3,4,5,6)
    

    You can build the bit in between the parentheses in PHP using implode()

提交回复
热议问题