Hi Guys,
I am looking to query a db having multiple brands of cars then from those results I want to further filter it based on the type of oil they use. I have written the below but it does not work and I am not sure how I can get this done.


I am trying to construct a mysql statement but I can't seem to get it right. I am pretty sure I can't use WHERE twice. Any help will be much appreciated.

SELECT *
FROM `details`
WHERE brand = 'audi' 
OR brand = 'toyota'
WHERE Oil ='Diesel'
SELECT * FROM `details` WHERE (brand = 'audi' OR brand = 'toyota') AND Oil = 'Diesel'

Thanks pritaeas , it worked like a charm

Hi,
I have a follow up question on this. Say the user selects oil as diesel and the leaves the brand section empty. Then how would I show cars which are based on diesel of all the brands.

The above code works but it only works if the brands are provided. I need to give the user the flexibility to just choice the type of oil too.

Thank you in advance.
Vishal

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.