Easy question. Let’s say I want to query the database table as such:
Cars bought in 2020
Engine size V8
Color red or black
Is the sql statement set up as:
SELECT * FROM table WHERE CarsBought = '2020' AND EngineSize = 'V8' AND Color = 'Red' OR Color = 'Black'
Assuming this shows all red cars with a V8 engine bought in 2020 and all black cars with any engine size and purchased anytime
Or as:
SELECT * FROM table WHERE CarsBought = '2020' AND EngineSize = 'V8' AND Color = 'Red' OR CarsBought = '2020' AND EngineSize = 'V8' AND Color = 'Black'
I assume this is the correct way
Do you have to do all the ANDs then the OR followed by all the ANDS again? This always confused me. Or can I say I want to see this AND this AND this OR this. Guess I’m looking for the easy way out without having such long lines of code