Search within MYSQL search results

Asked

Viewed 81 times

0

I have a situation more or less equal to that:

A table with the records, I need to do a search with two references, example select * from CARROS Where concessionaria= 'VW' or veiculo='VW' AND location ='São Paulo'

this search returns me all VW cars and regardless of location, it ignores the second condition.

I would need it to filter inside the "São Paulo" location to make a second filter bringing the data from cars or dealerships that I requested.

My score is like:

VW GOL SP

VW JETTA MG

it should prevent this second - because it is outside SP.

1 answer

1


His select is almost correct, but without the parentheses he ends up doing the following ( I’ll show parentheses for you to understand )

select * from CARROS where concessionaria= 'VW' or (veiculo='VW' AND localização ='São Paulo')

in which case it will catch whenever it is vw or is the combination of the two, but what you want is the following:

select * from CARROS where (concessionaria= 'VW' or veiculo='VW') AND localização ='São Paulo'
  • Thank you very much. That’s exactly what it was. Definition of prioritization. I put the parentheses in and it worked.

  • Lucas, what if I add another variable? , example: select * from CARROS Where (dealership= 'VW' or vehicle='VW') AND location ='São Paulo' and status = 'active'

  • in the latter case it is not filtering by status, because the results comes with information that is in the bank as "Inactive"

Browser other questions tagged

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