LINQ To SQL Samples - UNION ALL/UNION/INTERSECTOn This Page |
This sample uses Concat to return a sequence of all Customer and Employee phone/fax numbers.
Public Sub LinqToSqlUnion01()
Dim q = (From c In db.Customers Select c.Phone).Concat( _
From c In db.Customers Select c.Fax).Concat( _
From e In db.Employees Select e.HomePhone)
ObjectDumper.Write(q)
End Sub
Result:
030-0074321
(5) 555-4729
(5) 555-3932
(171) 555-7788
0921-12 34 65
0621-08460
88.60.15.31
(91) 555 22 82
91.24.45.40
(604) 555-4729
(171) 555-1212
(1) 135-5555
(5) 555-3392
0452-076545
(11) 555-7647
(171) 555-2282
0241-039123
40.67.88.88
(171) 555-0297
7675-3425
(11) 555-9857
(91) 555 94 44
20.16.10.16
0695-34 67 21
089-0877310
40.32.21.21
011-4988260
(1) 354-2534
(93) 203 4560
(95) 555 82 82
(11) 555-9482
(503) 555-7555
(2) 283-2951
(21) 555-0091
(5) 555-1340
(503) 555-6874
2967 542
(198) 555-8888
0555-09876
30.59.84.10
61.77.61.10
(604) 555-3392
(509) 555-7969
069-0245984
(415) 555-5938
(9) 331-6954
(8) 34-56-12
(503) 555-9573
035-640230
(02) 201 24 67
(514) 555-8054
0342-023176
(171) 555-7733
(1) 135-5333
(907) 555-7584
0221-0644327
(1) 42.34.22.66
(5) 552-3745
6562-9722
(1) 356-5634
(21) 555-4252
(11) 555-1189
0372-035188
(1) 123-5555
(505) 555-5939
0522-556721
(21) 555-3412
0897-034214
(91) 745 6200
07-98 92 35
(208) 555-8097
(171) 555-1717
31 12 34 56
(1) 47.55.60.10
(307) 555-4680
(071) 23 67 22 20
(503) 555-3612
(406) 555-5834
0251-031259
(5) 555-2933
(11) 555-2167
(206) 555-8257
86 21 32 43
78.32.54.86
26.47.15.10
0711-020361
981-443655
(14) 555-8122
(206) 555-4112
90-224 8858
(26) 642-7012
030-0076545
(5) 555-3745
null
(171) 555-6750
0921-12 34 67
0621-08924
88.60.15.32
(91) 555 91 99
91.24.45.41
(604) 555-3745
null
(1) 135-4892
(5) 555-7293
null
null
(171) 555-9199
0241-059428
40.67.89.89
(171) 555-3373
7675-3426
null
(91) 555 55 93
20.16.10.17
null
089-0877451
40.32.21.20
011-4988261
(1) 354-2535
(93) 203 4561
null
null
null
(2) 283-3397
(21) 555-8765
(5) 555-1948
(503) 555-2376
2967 3333
null
null
30.59.85.11
61.77.61.11
(604) 555-7293
(509) 555-6221
069-0245874
null
(9) 331-7256
(8) 34-93-93
(503) 555-9646
035-640231
(02) 201 24 68
(514) 555-8055
null
(171) 555-2530
(1) 135-5535
(907) 555-2880
0221-0765721
(1) 42.34.22.77
(5) 545-3745
6562-9723
null
(21) 555-4545
null
null
(1) 123-5556
(505) 555-3620
0522-556722
null
null
(91) 745 6210
07-98 92 47
null
(171) 555-5646
31 13 35 57
(1) 47.55.60.20
(307) 555-6525
(071) 23 67 22 21
null
(406) 555-8083
0251-035695
null
(11) 555-2168
(206) 555-2174
86 22 33 44
78.32.54.87
26.47.15.11
0711-035428
981-443655
null
(206) 555-4115
90-224 8858
(26) 642-7012
(206) 555-9857
(206) 555-9482
(206) 555-3412
(206) 555-8122
(71) 555-4848
(71) 555-7773
(71) 555-5598
(206) 555-1189
(71) 555-4444
This sample uses Concat to return a sequence of all Customer and Employee name and phone number mappings.
Public Sub LinqToSqlUnion02()
Dim q = (From c In db.Customers _
Select Name = c.CompanyName, Phone = c.Phone).Concat(From e In db.Employees _
Select Name = e.FirstName & " " & e.LastName, Phone = e.HomePhone)
ObjectDumper.Write(q)
End Sub
Result:
Name=Alfreds Futterkiste Phone=030-0074321
Name=Ana Trujillo Emparedados y helados Phone=(5) 555-4729
Name=Antonio Moreno Taquería Phone=(5) 555-3932
Name=Around the Horn Phone=(171) 555-7788
Name=Berglunds snabbköp Phone=0921-12 34 65
Name=Blauer See Delikatessen Phone=0621-08460
Name=Blondesddsl père et fils Phone=88.60.15.31
Name=Bólido Comidas preparadas Phone=(91) 555 22 82
Name=Bon app' Phone=91.24.45.40
Name=Bottom-Dollar Markets Phone=(604) 555-4729
Name=B's Beverages Phone=(171) 555-1212
Name=Cactus Comidas para llevar Phone=(1) 135-5555
Name=Centro comercial Moctezuma Phone=(5) 555-3392
Name=Chop-suey Chinese Phone=0452-076545
Name=Comércio Mineiro Phone=(11) 555-7647
Name=Consolidated Holdings Phone=(171) 555-2282
Name=Drachenblut Delikatessen Phone=0241-039123
Name=Du monde entier Phone=40.67.88.88
Name=Eastern Connection Phone=(171) 555-0297
Name=Ernst Handel Phone=7675-3425
Name=Familia Arquibaldo Phone=(11) 555-9857
Name=FISSA Fabrica Inter. Salchichas S.A. Phone=(91) 555 94 44
Name=Folies gourmandes Phone=20.16.10.16
Name=Folk och fä HB Phone=0695-34 67 21
Name=Frankenversand Phone=089-0877310
Name=France restauration Phone=40.32.21.21
Name=Franchi S.p.A. Phone=011-4988260
Name=Furia Bacalhau e Frutos do Mar Phone=(1) 354-2534
Name=Galería del gastrónomo Phone=(93) 203 4560
Name=Godos Cocina Típica Phone=(95) 555 82 82
Name=Gourmet Lanchonetes Phone=(11) 555-9482
Name=Great Lakes Food Market Phone=(503) 555-7555
Name=GROSELLA-Restaurante Phone=(2) 283-2951
Name=Hanari Carnes Phone=(21) 555-0091
Name=HILARION-Abastos Phone=(5) 555-1340
Name=Hungry Coyote Import Store Phone=(503) 555-6874
Name=Hungry Owl All-Night Grocers Phone=2967 542
Name=Island Trading Phone=(198) 555-8888
Name=Königlich Essen Phone=0555-09876
Name=La corne d'abondance Phone=30.59.84.10
Name=La maison d'Asie Phone=61.77.61.10
Name=Laughing Bacchus Wine Cellars Phone=(604) 555-3392
Name=Lazy K Kountry Store Phone=(509) 555-7969
Name=Lehmanns Marktstand Phone=069-0245984
Name=Let's Stop N Shop Phone=(415) 555-5938
Name=LILA-Supermercado Phone=(9) 331-6954
Name=LINO-Delicateses Phone=(8) 34-56-12
Name=Lonesome Pine Restaurant Phone=(503) 555-9573
Name=Magazzini Alimentari Riuniti Phone=035-640230
Name=Maison Dewey Phone=(02) 201 24 67
Name=Mère Paillarde Phone=(514) 555-8054
Name=Morgenstern Gesundkost Phone=0342-023176
Name=North/South Phone=(171) 555-7733
Name=Océano Atlántico Ltda. Phone=(1) 135-5333
Name=Old World Delicatessen Phone=(907) 555-7584
Name=Ottilies Käseladen Phone=0221-0644327
Name=Paris spécialités Phone=(1) 42.34.22.66
Name=Pericles Comidas clásicas Phone=(5) 552-3745
Name=Piccolo und mehr Phone=6562-9722
Name=Princesa Isabel Vinhos Phone=(1) 356-5634
Name=Que Delícia Phone=(21) 555-4252
Name=Queen Cozinha Phone=(11) 555-1189
Name=QUICK-Stop Phone=0372-035188
Name=Rancho grande Phone=(1) 123-5555
Name=Rattlesnake Canyon Grocery Phone=(505) 555-5939
Name=Reggiani Caseifici Phone=0522-556721
Name=Ricardo Adocicados Phone=(21) 555-3412
Name=Richter Supermarkt Phone=0897-034214
Name=Romero y tomillo Phone=(91) 745 6200
Name=Santé Gourmet Phone=07-98 92 35
Name=Save-a-lot Markets Phone=(208) 555-8097
Name=Seven Seas Imports Phone=(171) 555-1717
Name=Simons bistro Phone=31 12 34 56
Name=Spécialités du monde Phone=(1) 47.55.60.10
Name=Split Rail Beer & Ale Phone=(307) 555-4680
Name=Suprêmes délices Phone=(071) 23 67 22 20
Name=The Big Cheese Phone=(503) 555-3612
Name=The Cracker Box Phone=(406) 555-5834
Name=Toms Spezialitäten Phone=0251-031259
Name=Tortuga Restaurante Phone=(5) 555-2933
Name=Tradição Hipermercados Phone=(11) 555-2167
Name=Trail's Head Gourmet Provisioners Phone=(206) 555-8257
Name=Vaffeljernet Phone=86 21 32 43
Name=Victuailles en stock Phone=78.32.54.86
Name=Vins et alcools Chevalier Phone=26.47.15.10
Name=Die Wandernde Kuh Phone=0711-020361
Name=Wartian Herkku Phone=981-443655
Name=Wellington Importadora Phone=(14) 555-8122
Name=White Clover Markets Phone=(206) 555-4112
Name=Wilman Kala Phone=90-224 8858
Name=Wolski Zajazd Phone=(26) 642-7012
Name=Nancy Davolio Phone=(206) 555-9857
Name=Andrew Fuller Phone=(206) 555-9482
Name=Janet Leverling Phone=(206) 555-3412
Name=Margaret Peacock Phone=(206) 555-8122
Name=Steven Buchanan Phone=(71) 555-4848
Name=Michael Suyama Phone=(71) 555-7773
Name=Robert King Phone=(71) 555-5598
Name=Laura Callahan Phone=(206) 555-1189
Name=Anne Dodsworth Phone=(71) 555-4444
This sample uses Union to return a sequence of all countries that either Customers or Employees are in.
Public Sub LinqToSqlUnion03()
Dim q = (From c In db.Customers _
Select c.Country).Union(From e In db.Employees _
Select e.Country)
ObjectDumper.Write(q)
End Sub
Result:
Argentina
Austria
Belgium
Brazil
Canada
Denmark
Finland
France
Germany
Ireland
Italy
Mexico
Norway
Poland
Portugal
Spain
Sweden
Switzerland
UK
USA
Venezuela
This sample uses Intersect to return a sequence of all countries that both Customers and Employees live in.
Public Sub LinqToSqlUnion04()
Dim q = (From c In db.Customers _
Select c.Country).Intersect(From e In db.Employees _
Select e.Country)
ObjectDumper.Write(q)
End Sub
Result:
UK
USA
This sample uses Except to return a sequence of all countries that Customers live in but no Employees live in.
Public Sub LinqToSqlUnion05()
Dim q = (From c In db.Customers _
Select c.Country).Except(From e In db.Employees Select e.Country)
ObjectDumper.Write(q)
End Sub
Result:
Argentina
Austria
Belgium
Brazil
Canada
Denmark
Finland
France
Germany
Ireland
Italy
Mexico
Norway
Poland
Portugal
Spain
Sweden
Switzerland
Venezuela