Syntax to put more than one id to pick up certain products from the bank

Asked

Viewed 18 times

1

I’d like to get more than one bank ID, because I can only pull one. I think it must be the syntax that is wrong.`

$sql = "SELECT * FROM camiseta_Masc WHERE id =1,2,3";

`

1 answer

2


Yes, it’s a syntax error.

One solution is this:

$sql = "SELECT * FROM camiseta_Masc WHERE id IN (1,2,3)";

See working on SQL FIDDLE.

Errors of this nature can be solved by reading the language manual.


If there were no IN:

$sql = "SELECT * FROM camiseta_Masc WHERE id=1 OR id=2 OR id=3";

See working on SQL FIDDLE.


Just out of curiosity, IN could be used "backwards" if you wanted to find a value in more than one field, instead of more than one value in a field:

SELECT nome WHERE 3107 IN ( codigo, codigo_master );

Browser other questions tagged

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