Does not work SQL

Asked

Viewed 31 times

0

I have this SQL function in a php code but I’m not getting the data requested 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?

  • Maybe it should be manutencao = 'Equipamento' AND manutencao = 'Material de saude' or something similar... failed to inform the name of the field

  • Material de saude would be the q?

  • Health material is what is written in with maintenance field

3 answers

1

It is necessary to inform the field where the Where must 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. Will always return 0.

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

SELECT * 
FROM participacao 
WHERE manutencao IN ('Equipamento', 'Material de saude') 
ORDER BY Id DESC
  • does not work in the same

  • I edited my answer. Checks whether it’s over or don’t you need.

  • Thank you but I’ve already decided, you can see up how I put it, but thank you the same

1

If you want to check whether the value is one or the other, the correct 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 reported in the query. With OR, you pull if a value equal to one or the other, that is, all with "Equipment" and all the "Health material".

  • I really want the AND because they are 2 that I want to show

  • @Adelinovasconcelos Pois eh Adelino. It is impossible to show two things of the same column with two different values using AND.

  • then how should I do

  • @Adelinovasconcelos The way I responded, using OR, which will pick up one thing or another.

  • i intend the 2 things because the whole has 3 that I intend 2

  • @Adelinovasconcelos So, if the value is 'Equipment" or "Health material", will return everything that has one of these two values.

  • but still has another value Workshop

  • @Adelinovasconcelos The "Workshop" will not enter.

  • correct,I intend to appear only the other two

  • @Adelinovasconcelos Can use the OR normally, saying what you want to return.

  • @Adelinovasconcelos When you put AND, you’re saying it has to be THE TWO VALUES at the same time, and not one or the other.

  • I’ve done it but thank you all the same

  • @Good. Mark the answer with . This will help people in the future who have the same problem. Abs!

  • not for two days

  • @Adelinovasconcelos Wow, why?

Show 10 more comments

0

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

$query_part = "SELECT * FROM participacao WHERE NOT manutencao = 'Oficina' ORDER BY Id DESC";

Browser other questions tagged

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