BaşlayınÜcretsiz Başlayın

UNION and UNION ALL

You want a query that returns all cities listed in the Earthquakes database. It should be an easy query on the Cities table. However, to be sure you get all cities in the database you will append the query to the Nations table to include capital cities as well. You will use UNION to remove any duplicate rows.

Out of curiosity, you want to know if there were any duplicate rows. If you do the same query but append with UNION ALL instead, and compare the number of rows returned in each query, UNION ALL will return more rows if there are duplicates.

Bu egzersiz

Improving Query Performance in SQL Server

kursunun bir parçasıdır
Kursu Görüntüle

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

SELECT ___ AS NearCityName, -- City name column
	   CountryCode
FROM Cities

___ -- Append queries

SELECT ___ AS NearCityName, -- Nation capital column
       Code2 AS CountryCode
FROM Nations;
Kodu Düzenle ve Çalıştır