Query Mysql comparing to PHP array

Asked

Viewed 38 times

0

I need to mount an SQL query to search for more than one value.

Type:

SELECT * FROM tabela WHERE id = 10 OR id = 20 .....

But I found this option:

SELECT * FROM tabela WHERE id IN (' . implode(',', array_map('intval', $idgrupos)) . ')

It works, but the problem is that the id has to be equal to all idgroups passed in the array. I wanted it to come back if I found at least one like it in the array. How do I?

  • "has to be the same as everyone"? What do you mean? The clause in checks if the value is contained in a list.

  • The IN clause as the name says checks if the id is within the elements cited within the parenthesis: i.e., SELECT * FROM table where id IN (1,2,3,4,5): if one of the id is between 1 and 5, it will return as many as it finds, so in my table it has the ids 2 , 3 , 6 , the quoted SELECT will return the line with ids 2 and 3 as they are "IN" in this possible set (1,2,3,4,5)

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.