select sex, id from qualification where cid = ('Male' or 'Female')
vs
select sex, id from qualification where cid = 'Male' or cid = 'Female'
The first code would generate all of the items while the second gives what I want.
In a sense, we can't have or in a brackets for sql?
 
                        
MySQL normally
casta value to another type for our convenience. One example of it would be casting a string into number.MySQL can cast a string into a number by relying on the leading number of the said string. For example:
This has been discussed before on another QA as Gelu pointed out.
On another note,
truerepresented as1andfalserepresented as0in bit.Now let's examine your query:
Lets resolve bit-by-bit on the
whereclause.The
oroperator accepts twobooleanoperand. On your case that would be'Male'and'Female'. Based on how MySQL handles casting, both'Male'and'Female'would return as 0 given they have no leading number at all.An
orwith both operand valued asfalsewill resultfalse. After resolving the('Male' or 'Female')thewhereclause will be:With the assumption that
cidcolumn contains string without any leading number at all, we can assert that allcidcasted as0. It will result your query to be rewritten as:Which also meant:
The query above will return all rows.
Edit: Major restructuring on the answer. I feel the previous answer might be a bit confusing.