Hi,
I want the db to return records which have either "bmw" or "audi". Below is my code but the db only shows records which have bmw.
SELECT * FROM `details` WHERE BRAND = 'bmw' OR 'audi' Thank you in advance.
Cheers,
Vishal
Hi,
I want the db to return records which have either "bmw" or "audi". Below is my code but the db only shows records which have bmw.
SELECT * FROM `details` WHERE BRAND = 'bmw' OR 'audi' Thank you in advance.
Cheers,
Vishal
Quick diagnosis and the fix summarized
The WHERE clause in the original query used a bare string literal on one side of OR, so the database treated that literal as a non-boolean expression and it had no effect — which explains why only the rows matching the first comparison showed up. As noted, the correct approach is to compare the column to each value or use the IN shorthand so the engine checks the column against both candidates.
Practical checklist to avoid this class of bug
Verify what values are actually stored (different case, extra spaces, typos). For a quick check, list distinct BRAND values.
Be aware that string comparisons respect the column collation (case sensitivity). If needed, normalize data on insert or use a case-insensitive collation so matches behave as expected. Using functions like LOWER() to compare will work but can prevent index use — consider normalizing the data or adding a generated column you can index instead.
NULLs and leading/trailing whitespace can mask matches. Trim and handle NULLs explicitly when cleaning data or writing conditions.
For safety and maintainability, parameterize user input rather than constructing SQL strings directly.
References
MySQL type-conversion and expression evaluation (explains how non-boolean literals are coerced): MySQL Manual — Type Conversion in Expression Evaluation
Comparison operators including IN and the behavior of comparisons: MySQL Manual — Comparison Operators
This addresses why only the first brand matched and adds practical checks (distinct values, collation, trimming, indexing) beyond the correction suggested by .
Jump to Post— d5e5 109SELECT * FROM details WHERE BRAND IN('bmw', 'audi')Alternatively you can say
WHERE BRAND = 'bmw' OR BRAND = 'audi'
SELECT *
FROM details
WHERE BRAND IN('bmw', 'audi') Alternatively you can say WHERE BRAND = 'bmw' OR BRAND = 'audi'
thank you :)
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.