Syntax for placing more than one id to get certain products from the bank

1

I wanted to get more than one id from the bank, since 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";

'

    
asked by anonymous 02.11.2017 / 18:52

1 answer

2

Yes, it is syntax error.

One solution is this:

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

See working in SQL FIDDLE .

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


If there was no IN :

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

See working on SQL FIDDLE .


Just curious, 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 );
    
02.11.2017 / 18:53