MySQL UNION关键字

MySQL UNION关键字

使用UNION,如果想从几个表选择行一前一后的所有作为一个单一的结果集,或几个集合行在单一的表中。

UNION是从MySQL4.0开始使用。本节说明如何使用它。

假设有两个表,列出潜在和实际的客户,第三个表,列出供应商购买耗材,并且希望通过从所有三个表合并名称和地址,以创建一个单一的邮件列表。UNION提供了一种方法来做到这一点。假设这三个表具有以下内容:

mysql> SELECT * FROM prospect;
+---------+-------+------------------------+
| fname   | lname | addr                   |
+---------+-------+------------------------+
| Peter   | Jones | 482 Rush St., Apt. 402 |
| Bernice | Smith | 916 Maple Dr.          |
+---------+-------+------------------------+
mysql> SELECT * FROM customer;
+-----------+------------+---------------------+
| last_name | first_name | address             |
+-----------+------------+---------------------+
| Peterson  | Grace      | 16055 Seminole Ave. |
| Smith     | Bernice    | 916 Maple Dr.       |
| Brown     | Walter     | 8602 1st St.        |
+-----------+------------+---------------------+
mysql> SELECT * FROM vendor;
+-------------------+---------------------+
| company           | street              |
+-------------------+---------------------+
| ReddyParts, Inc.  | 38 Industrial Blvd. |
| Parts-to-go, Ltd. | 213B Commerce Park. |
+-------------------+---------------------+

这不要紧,如果所有的三个表都是不同的列名称。 以下查询说明如何从三个表一次全部选择名称和地址:

mysql> SELECT fname, lname, addr FROM prospect
-> UNION
-> SELECT first_name, last_name, address FROM customer
-> UNION
-> SELECT company, '', street FROM vendor;
+-------------------+----------+------------------------+
| fname             | lname    | addr                   |
+-------------------+----------+------------------------+
| Peter             | Jones    | 482 Rush St., Apt. 402 |
| Bernice           | Smith    | 916 Maple Dr.          |
| Grace             | Peterson | 16055 Seminole Ave.    |
| Walter            | Brown    | 8602 1st St.           |
| ReddyParts, Inc.  |          | 38 Industrial Blvd.    |
| Parts-to-go, Ltd. |          | 213B Commerce Park.    |
+-------------------+----------+------------------------+

如果想选择所有记录,包括重复的记录,请使用UNION关键字后面接一个 ALL 关键字:

mysql> SELECT fname, lname, addr FROM prospect
-> UNION ALL
-> SELECT first_name, last_name, address FROM customer
-> UNION
-> SELECT company, '', street FROM vendor;
+-------------------+----------+------------------------+
| fname             | lname    | addr                   |
+-------------------+----------+------------------------+
| Peter             | Jones    | 482 Rush St., Apt. 402 |
| Bernice           | Smith    | 916 Maple Dr.          |
| Grace             | Peterson | 16055 Seminole Ave.    |
| Bernice           | Smith    | 916 Maple Dr.          |
| Walter            | Brown    | 8602 1st St.           |
| ReddyParts, Inc.  |          | 38 Industrial Blvd.    |
| Parts-to-go, Ltd. |          | 213B Commerce Park.    |
+-------------------+----------+------------------------+

89 Responses

  1. Gtpmsi说道:

    lasix canada doxycycline 100mg without prescription albuterol inhalator generic

  2. Bxzfmf说道:

    buy escitalopram 10mg without prescription revia 50mg for sale buy naltrexone 50 mg sale

  3. Nssngq说道:

    cost strattera 10mg buy atomoxetine generic purchase sertraline online

  4. Gscqsu说道:

    buy zithromax online neurontin 800mg pills purchase gabapentin online

  5. Wpppyl说道:

    actigall for sale order cetirizine 5mg generic order zyrtec 10mg generic

  6. Rwrvlj说道:

    buy deltasone generic accutane 40mg usa where can i buy amoxil

  7. Qxhvim说道:

    strongest prescription antacid heartburn pills over the counter burping medication australia

  8. Ylssbv说道:

    get estrogen prescription online how to naturally last longer stronger ejaculation pills

  9. Uhnifi说道:

    non bleeding erosive gastropathy biopsied medication foe errosive gastritis over the counter urinary tract infection meds

  10. Iohxvl说道:

    purchase duloxetine sale modafinil cost order provigil generic

  11. Ghlcqz说道:

    anti fungal tablets for skin abruptly stopping blood pressure medication high blood pressure medicine list

  12. Ldbrxy说道:

    cyproheptadine for sale cyproheptadine 4mg brand order nizoral 200mg pills

  13. Mtmnnj说道:

    buy herpes treatment online ordering valtrex overnight delivery drugs to treat prediabete

  14. Gcihjt说道:

    brand medroxyprogesterone medroxyprogesterone ca buy hydrochlorothiazide without a prescription

  15. Cozwmx说道:

    new medications for smoking cessation best prescription to stop smoking buy pain pills online usa

  16. Bbszwc说道:

    letrozole 2.5mg generic cost abilify order aripiprazole 30mg online cheap

  17. Hkawbd说道:

    where to buy zopiclone pills sleeping pills non prescription uk virtual weight loss clinic

  18. Ntpwez说道:

    where to buy minocin without a prescription minocin 100mg drug buy requip 2mg

  19. Kuktwh说道:

    order alfuzosin 10 mg pill buy alfuzosin 10 mg sale best medicine for heartburn relief

  20. Zvjyht说道:

    buy generic clonidine over the counter buy generic tiotropium for sale order generic tiotropium bromide 9 mcg

  21. Pmlvxu说道:

    get acne pills online best pimple medication for teenagers buy oxcarbazepine medication

  22. Oftsmr说道:

    amoxicillin 250mg us arimidex tablet biaxin order

  23. Typtmw说道:

    buy calcitriol 0.25 mg pill order fenofibrate sale buy tricor 200mg online cheap

  24. Qitagt说道:

    academic writing services uk dissertation in accounting suprax oral

  25. Jreakc说道:

    academic writing best real money casino free roulette games

  26. Dqxgnb说道:

    aspirin 75 mg ca order aspirin 75 mg online blackjack online real money

  27. Skffyk说道:

    buy trazodone 100mg buy trazodone 100mg generic clindac a order

  28. Rawcpt说道:

    purchase tadacip for sale tadalafil 20mg usa indocin pill

  29. Agcedv说道:

    brand ceftin buy ceftin online cheap robaxin 500mg pills

  30. Pnbpmc说道:

    retin cream brand avanafil 200mg brand avana online order

  31. Gcsbnl说道:

    buy tamoxifen no prescription buy symbicort for sale purchase budesonide

  32. Fobaay说道:

    order generic cleocin order generic erythromycin 500mg order sildenafil 50mg pills

  33. Gcgqia说道:

    lamotrigine 50mg canada buy generic lamotrigine 200mg buy vermox 100mg online cheap

  34. Wvidny说道:

    metronidazole cheap flagyl medication buy cephalexin 500mg generic

  35. Nemdms说道:

    buy aurogra generic cost aurogra 50mg estradiol order

  36. Hphyji说道:

    fluconazole 200mg usa acillin pills baycip brand

  37. Atbxaz说道:

    oral spironolactone 100mg propecia order brand propecia 1mg

  38. Jdiwoj说道:

    order motilium 10mg without prescription buy coreg cheap generic sumycin 250mg

  39. Chwpwq说道:

    tamsulosin usa ondansetron 4mg cheap buy simvastatin for sale

  40. Pogwgt说道:

    buy buspirone 5mg online cordarone 100mg over the counter order amiodarone 200mg pill

  41. Ettedk说道:

    ranitidine 150mg over the counter zantac ca order celecoxib 200mg pill

  42. Csogsg说道:

    allopurinol 300mg generic buy rosuvastatin without a prescription crestor 10mg cheap

  43. Qkyigz说道:

    order imitrex 50mg generic buy dutasteride generic buy generic avodart

  44. Zkbqao说道:

    buy azelastine sprayer order acyclovir 400mg pills purchase irbesartan generic

  45. Bsccls说道:

    order esomeprazole 20mg capsules order mirtazapine 30mg for sale topiramate canada

  46. Icuycc说道:

    buy pepcid 40mg generic buy prograf no prescription tacrolimus brand

  47. Tajfgp说道:

    buy glimepiride 1mg online cheap purchase cytotec arcoxia order

  48. Kdkybl说道:

    buy pamelor order nortriptyline 25 mg without prescription cost acetaminophen 500mg

  49. Lctrzr说道:

    order inderal 20mg sale clopidogrel sale clopidogrel 150mg pills

  50. Jdwaxw说道:

    fosamax 70mg over the counter buy fosamax paypal furadantin 100 mg ca

  51. Qcdwza说道:

    order baclofen 10mg online order ozobax online cheap toradol without prescription

  52. Erjjmc说道:

    loratadine 10mg pill buy tritace without a prescription dapoxetine 60mg sale

  53. Gnvymz说道:

    cost baclofen 10mg buy toradol cost ketorolac

  54. Xjbemn说道:

    order dilantin 100mg pills cost flexeril purchase oxybutynin generic

  55. Ognkcu说道:

    buy generic vardenafil 20mg order digoxin without prescription buy tizanidine without a prescription

  56. Dzvmvx说道:

    medrol 8 mg without prescription brand aristocort buy triamcinolone 10mg generic

  57. Jcqcqj说道:

    clomiphene pills purchase isosorbide generic order imuran 25mg for sale

  58. Gjcruf说道:

    symmetrel pill buy tenormin medication cost dapsone 100 mg

  59. Mpaznt说道:

    online blackjack live dealer buy augmentin 375mg generic cheap synthroid 100mcg

  60. Ngmgpu说道:

    ladbrokes uk order stromectol generic generic stromectol for humans

  61. Rwnzye说道:

    cost protonix 40mg order pantoprazole 40mg pill pyridium pill

  62. Jhvgvi说道:

    play blackjack casino games online buy albuterol paypal albuterol pills

  63. Dbtduw说道:

    online casino slots no download blackjack for money buy lasix 100mg

  64. Wedoin说道:

    atorvastatin pills buy norvasc without prescription buy norvasc cheap

  65. Oktuyz说道:

    buy azithromycin 250mg online purchase prednisolone online cheap gabapentin generic

  66. Gamksk说道:

    purchase cefdinir without prescription buy lansoprazole 30mg online buy prevacid 30mg pills

  67. Bjdkjy说道:

    accutane 40mg sale buy azithromycin 250mg buy zithromax 500mg pills

  68. Kguyjb说道:

    buy provigil 200mg for sale order provigil 100mg generic order prednisone 10mg without prescription

  69. Xljepo说道:

    order generic cenforce 50mg order aralen 250mg pills order chloroquine 250mg online cheap

  70. Kgsctz说道:

    buy telmisartan 20mg for sale buy molnupiravir 200mg sale molnupiravir 200 mg ca

  71. Trusmp说道:

    buy tadalafil 10mg pills cialis 40mg over the counter order viagra 50mg

  72. Mzrsuz说道:

    order omeprazole 20mg for sale order generic singulair metoprolol pill

  73. Marafy说道:

    buy premarin 0.625mg sale purchase sildenafil sale sildenafil 100mg for sale

  74. Omwnmu说道:

    buy vasotec 5mg pills purchase doxazosin sale buy cheap generic duphalac

  75. Zlgman说道:

    zovirax order exelon pills purchase exelon generic

  76. Zpluar说道:

    order generic ferrous sulfate cheap sotalol 40mg buy sotalol online

  77. Didtpk说道:

    pyridostigmine ca piroxicam 20mg without prescription purchase maxalt online cheap

  78. Rzgejq说道:

    order florinef online cheap order loperamide 2 mg online buy imodium online cheap

  79. Iryval说道:

    etodolac 600 mg price order mebeverine generic cilostazol 100mg us

  80. Omxvvv说道:

    buy dydrogesterone 10mg generic jardiance 25mg for sale generic empagliflozin 25mg

  81. Fctawo说道:

    buy dipyridamole online buy plendil 5mg sale pravastatin 10mg usa

  82. Qkbhiw说道:

    cost meloset danocrine 100mg usa danocrine 100mg cost

  83. Mmqngs说道:

    aspirin order brand aspirin zovirax over the counter

  84. Bqpucd说道:

    purchase precose sale generic repaglinide 2mg order griseofulvin 250 mg pills

  85. Cddpsn说道:

    buy generic minoxidil over the counter order mintop online buy ed pills gb

  86. Jgrahp说道:

    buy zaditor 1mg pills ketotifen uk imipramine 25mg for sale

  87. Upcvqx说道:

    tadalafil online viagra 50mg pills for men purchase viagra pill

  88. Gttwgr说道:

    buy tricor 160mg online cheap tricor cost order fenofibrate 160mg sale

发表评论

您的电子邮箱地址不会被公开。

CAPTCHAis initialing...