my table schema as follows:
+------+-------+-------+
| id | name1 | name2 |
+------+-------+-------+
| 1 | A | B |
| 2 | A | C |
| 3 | B | A |
| 4 | C | D |
+------+-------+-------+
and i am using the query as follows:
select * from t where name1='A' or name1='B' and name2='C';
and the result as follows
+------+-------+-------+
| id | name1 | name2 |
+------+-------+-------+
| 1 | A | B |
| 2 | A | C |
+------+-------+-------+
How this result came and
I want the query which returns the row that in which the name1 will be A or B and name2 to be ‘B’
the query result should be like this
+------+-------+-------+
| id | name1 | name2 |
+------+-------+-------+
| 1 | A | B |
+------+-------+-------+
I want the result from the query using only “AND” and “OR” operation…
I suggest you read up about boolean logic. This is a very simple operation, so if you were familiar with B.L., you’d have been able to do this yourself.
That being said, these two states will accomplish what you want: