Reputation: 95
I have this query:
SELECT * FROM Sales
WHERE (Date BETWEEN '2017-01-01' AND '2017-02-28')
AND (ID="Search" OR Product="Search");
It should return only sales between those 2 dates that have either ID os Product equal search, but it's returning all results that are between those dates even if neither ID or product = Search, and I don't understand why
Edit
Sample Data
ID Date Product
1 2017-01-11 Product A
2 2017-02-01 Product C
3 2017-02-05 Product B
4 2017-03-01 Product A
If my query is
SELECT * FROM Sales
WHERE (Date BETWEEN '2017-01-01' AND '2017-02-28')
AND (ID="Product C" OR Product="Product C");
I was expecting
ID Date Product
2 2017-02-01 Product C
But it returns
ID Date Product
1 2017-01-11 Product A
2 2017-02-01 Product C
3 2017-02-05 Product B
Thanks in advance
Upvotes: 1
Views: 52
Reputation: 51
It's no problem with it. for example,
my table
+----+------+---------------------+
| id | name | create_at |
+----+------+---------------------+
| 1 | 1 | 2017-03-04 11:06:25 |
| 2 | 2 | 2017-03-04 11:09:27 |
| 3 | 4 | 2017-03-04 11:06:56 |
+----+------+---------------------+
my sql
SELECT * FROM test
WHERE (create_at BETWEEN '2017-03-04 11:06:00' AND '2017-03-04 11:10:00')
AND (id="2" OR name="2");
my result
+----+------+---------------------+
| id | name | create_at |
+----+------+---------------------+
| 2 | 2 | 2017-03-04 11:09:27 |
+----+------+---------------------+
Upvotes: 1