我在數據庫中查詢數據,如下表具有的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