I have to query data in the database, have the following table
COLUMNS: Type, Location, name, etc.
DATA:
1. Stores in NJ, name = xyz
2. Restaurants in NY
3. Hotels in US
4. Stores in PA
5. Restaurants in VA
6. Hotels in MD
7. Stores in NJ, name = abc
8. etc.
I need a query, to fetch the data from 1, 2, 3
Right now, I have the following query. This runs faster. But is there any other query I can use without UNION
select type, location from table1
where type='stores' and location='NJ' and name='XYZ'
UNION
select type, location from table1
where type='restaurants' and location='NY'
UNION
select type, location from table1
where type='hotels' and location='US'
unionin a situation like this. It will try to do adistinct, which means that you're unnecessarily de-duplicating.