Search within MYSQL search results [closed]

0

I have a situation more or less like this:

A table with the records, I need to do a search with two references, example select * from CARS where dealership = 'VW' or vehicle = 'VW' AND location = 'Sao 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 location "São Paulo" would make a second filter bringing the data of cars or dealerships that I ordered.

My result is type:

VW GOL SP

VW JETTA MG

It should prevent this second - because it is out of SP.

    
asked by anonymous 03.11.2018 / 16:27

1 answer

1

Your select is almost correct, but without the parentheses it ends up doing the following (I'll show you with parentheses for you to understand)

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

In this case it will pick up whenever it is vw or it 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'
    
03.11.2018 / 16:35