Sql server® 2012 t-sql fundamentals


   Microsoft SQL Server 2012 T-SQL Fundamentals Self-Contained Multivalued Subquery examples



Download 10,93 Mb.
Pdf ko'rish
bet188/443
Sana26.01.2022
Hajmi10,93 Mb.
#411755
1   ...   184   185   186   187   188   189   190   191   ...   443
Bog'liq
BookSQL

132  

Microsoft SQL Server 2012 T-SQL Fundamentals



Self-Contained Multivalued Subquery examples

A multivalued subquery is a subquery that returns multiple values as a single column, regardless of 

whether the subquery is self-contained. Some predicates, such as the IN predicate, operate on a mul-

tivalued subquery. 



note

  There are other predicates that operate on a multivalued subquery; those are SOME



ANY, and ALL. They are very rarely used and therefore not covered in this book. 

The form of the IN predicate is:



 IN ()

The predicate evaluates to TRUE if scalar_expression is equal to any of the values returned by the 

subquery. Recall the last request discussed in the previous section—returning order IDs of orders that 

were handled by employees with a last name starting with a certain letter. Because more than one 

employee can have a last name starting with the same letter, this request should be handled with the 

IN predicate and a multivalued subquery, and not with an equality operator and a scalar subquery. 

For example, the following query returns order IDs of orders placed by employees with a last name 

starting with D.

SELECT orderid 

FROM Sales.Orders 

WHERE empid IN 

  (SELECT E.empid 

   FROM HR.Employees AS E 

   WHERE E.lastname LIKE N'D%');

Because it uses the IN predicate, this query is valid with any number of values returned—none, 

one, or more. This query returns the following output, shown here in abbreviated form.

orderid 


----------- 

10258 


10270 

10275 


10285 

10292 


... 

10978 


11016 

11017 


11022 

11058 


 

(166 row(s) affected)

www.it-ebooks.info




Download 10,93 Mb.

Do'stlaringiz bilan baham:
1   ...   184   185   186   187   188   189   190   191   ...   443




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish