我在数据库中查询数据,如下表具有的Oracle SQL查询重写
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.
我需要一个查询,从1,2取数据,3
现在,我有以下查询。这运行得更快。但是否有任何其他查询,我可以使用,而不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'
不要在这种情况下使用'union'。它会尝试做一个“独特”的,这意味着你不必要的去重复。 – Ben