Bir sorgunun sonucu, diğer sorgunun koşulunu sağlaması durumunda bu tip sorgulara alt sorgular denir.
use Northwind --veritabanımıza veri ekledik, boş geçtiğimiz değerler NULL olarak atandı. insert Products (productName,UnitPrice,UnitsInStock,UnitsOnOrder) values ('Jolly',22.00,45,6) --categoryID si 7 olan ürünlerin productName'i güncelledik. update Products set ProductName='AKATA' where CategoryID=7
--Ürünler tablosundaki toplam stok miktarını alias (as) ile toplam stok adı altında gösterdik. '[]' tek kelimelik isimlendirme de kullanmaya gerek yok. select SUM(UnitsInstock) as [toplam stok] from Products --Chief adında bir tablo oluşturalım create table Chief ( ChiefId int Identity(1,1), ChiefName nvarchar (20), ChiefLastName nvarchar (20), GSM nvarchar (11) ) --tablomuza yeni veriler ekledik. insert Chief values('Ahmet','Gezer','06543456545'), ('Emel','Akar','5555678769'), ('Ayşe','Solmaz','5553467892') --alt sorgu: En altta yazdığımız sorgunun sonucu,üzerindeki sorgunun koşulunu getirmiş oldu. select orderID from orders where customerId in (select CustomerID from Customers where CompanyName='Alfreds Futterkiste') select productName from Products where ProductID in( (select ProductID from [Order Details] where OrderID in (select OrderId from orders where OrderDate ='1996-07-04'))) select Distinct(shipcountry) from Orders where EmployeeID=( select EmployeeID from Employees where FirstName='steven')