SQL does not work

0

I have this SQL function in a php code but I am not going to fetch the requested data from the database

$query_part = "SELECT * 
FROM participacao 
WHERE manutencao = 'Equipamento' AND 'Material de saude' ORDER BY Id DESC";

How should I write it or do it?

    
asked by anonymous 23.12.2017 / 02:22

3 answers

1

You need to enter the field where where should filter.

SELECT * 
FROM participacao 
WHERE manutencao = 'Equipamento'
AND NOME-DO-CAMPO = 'Material de saude' 
ORDER BY Id DESC

If you want manutencao = 'Equipamento' AND manutencao = 'Material de saude' , this is not possible. It will always return 0.

Depending on which data you want to return, you can use the following:

SELECT * 
FROM participacao 
WHERE manutencao IN ('Equipamento', 'Material de saude') 
ORDER BY Id DESC
    
23.12.2017 / 02:23
1

If you want to check whether the value is one or the other, the correct one is to use OR :

$query_part = "SELECT * 
FROM participacao 
WHERE manutencao = 'Equipamento' OR manutencao = 'Material de saude' ORDER BY Id DESC";
  

When using AND, you want the value of the field to be   two values entered in the query. With OR, you pull a value equal to one or the other, that is, all with "Equipment" and all "Health".

    
23.12.2017 / 02:27
0

For those who have the same doubt that I have here a Tip

$query_part = "SELECT * FROM participacao WHERE NOT manutencao = 'Oficina' ORDER BY Id DESC";
    
23.12.2017 / 02:43