Reputation: 2551
I want to set the condition using AND
and OR
in WHERE
clause. But the problem is AND condition is not setting to all other OR
Condition
ex:
SELECT
Item,
Name,
Brand,
Date,
StoreID
FROM
Item
WHERE
Date between '01-01-2017' and '30-01-2017'
OR Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo'
In my scenario I cannot use IN to select multiple Brand. So I want to set all Date filter to all the brands. How can I achieve it.
Thanks
Upvotes: 0
Views: 62
Reputation: 1889
We have two Scenario here as follows
SELECT
Item,
Name,
Brand,
Date,
StoreID
FROM
Item
WHERE
Date between '01-01-2017' and '30-01-2017'
OR (Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo')
SELECT
Item,
Name,
Brand,
Date,
StoreID
FROM
Item
WHERE
Date between '01-01-2017' and '30-01-2017'
AND (Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo')
Upvotes: 1
Reputation: 1555
SELECT
Item,
Name,
Brand,
Date,
StoreID
FROM
Item
WHERE
Date between '01-01-2017' and '30-01-2017'
AND ( Brand = 'Nike' or Brand = 'Jhonson' OR Brand = 'Polo')
It can be right with your result.
Upvotes: 0
Reputation: 2044
This would give you the all the results that match both clauses
WHERE
(Date between '01-01-2017' and '30-01-2017')
AND
(Brand IN ('Nike','Jhonson','Polo'))
This would give you everything that matches any of the clauses
WHERE
(Date between '01-01-2017' and '30-01-2017')
OR
(Brand IN ('Nike','Jhonson','Polo'))
Upvotes: 1