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.    |
+-------------------+----------+------------------------+

127 Responses

  1. Jjkuwh说道:

    order depo-medrol – order triamcinolone sale aristocort 4mg us

  2. Kiqtdq说道:

    omeprazole 20mg cost – tenormin 100mg for sale atenolol online buy

  3. Byfocy说道:

    buy cenforce 50mg online – order cenforce 50mg generic buy metformin 500mg without prescription

  4. Xxedqc说道:

    purchase viagra for sale – prices of cialis cialis 40mg price

  5. Wafjgz说道:

    buy vibra-tabs pills – order glucotrol 10mg without prescription buy glipizide 5mg generic

  6. Kzkzys说道:

    how to get omnacortil without a prescription – buy omnacortil 5mg pills progesterone tablet

  7. Ftrhjk说道:

    buy zithromax online – buy zithromax medication buy nebivolol 5mg

  8. Qrniii说道:

    amoxicillin without prescription – order generic valsartan order ipratropium for sale

  9. Zywfat说道:

    isotretinoin 10mg cost – order isotretinoin 40mg pills buy generic linezolid for sale

  10. Gtpmsi说道:

    lasix canada doxycycline 100mg without prescription albuterol inhalator generic

  11. Bxzfmf说道:

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

  12. Nssngq说道:

    cost strattera 10mg buy atomoxetine generic purchase sertraline online

  13. Gscqsu说道:

    buy zithromax online neurontin 800mg pills purchase gabapentin online

  14. Wpppyl说道:

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

  15. Rwrvlj说道:

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

  16. Qxhvim说道:

    strongest prescription antacid heartburn pills over the counter burping medication australia

  17. Ylssbv说道:

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

  18. Uhnifi说道:

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

  19. Iohxvl说道:

    purchase duloxetine sale modafinil cost order provigil generic

  20. Ghlcqz说道:

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

  21. Ldbrxy说道:

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

  22. Mtmnnj说道:

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

  23. Gcihjt说道:

    brand medroxyprogesterone medroxyprogesterone ca buy hydrochlorothiazide without a prescription

  24. Cozwmx说道:

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

  25. Bbszwc说道:

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

  26. Hkawbd说道:

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

  27. Ntpwez说道:

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

  28. Kuktwh说道:

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

  29. Zvjyht说道:

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

  30. Pmlvxu说道:

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

  31. Oftsmr说道:

    amoxicillin 250mg us arimidex tablet biaxin order

  32. Typtmw说道:

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

  33. Qitagt说道:

    academic writing services uk dissertation in accounting suprax oral

  34. Jreakc说道:

    academic writing best real money casino free roulette games

  35. Dqxgnb说道:

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

  36. Skffyk说道:

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

  37. Rawcpt说道:

    purchase tadacip for sale tadalafil 20mg usa indocin pill

  38. Agcedv说道:

    brand ceftin buy ceftin online cheap robaxin 500mg pills

  39. Pnbpmc说道:

    retin cream brand avanafil 200mg brand avana online order

  40. Gcsbnl说道:

    buy tamoxifen no prescription buy symbicort for sale purchase budesonide

  41. Fobaay说道:

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

  42. Gcgqia说道:

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

  43. Wvidny说道:

    metronidazole cheap flagyl medication buy cephalexin 500mg generic

  44. Nemdms说道:

    buy aurogra generic cost aurogra 50mg estradiol order

  45. Hphyji说道:

    fluconazole 200mg usa acillin pills baycip brand

  46. Atbxaz说道:

    oral spironolactone 100mg propecia order brand propecia 1mg

  47. Jdiwoj说道:

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

  48. Chwpwq说道:

    tamsulosin usa ondansetron 4mg cheap buy simvastatin for sale

  49. Pogwgt说道:

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

  50. Ettedk说道:

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

  51. Csogsg说道:

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

  52. Qkyigz说道:

    order imitrex 50mg generic buy dutasteride generic buy generic avodart

  53. Zkbqao说道:

    buy azelastine sprayer order acyclovir 400mg pills purchase irbesartan generic

  54. Bsccls说道:

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

  55. Icuycc说道:

    buy pepcid 40mg generic buy prograf no prescription tacrolimus brand

  56. Tajfgp说道:

    buy glimepiride 1mg online cheap purchase cytotec arcoxia order

  57. Kdkybl说道:

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

  58. Lctrzr说道:

    order inderal 20mg sale clopidogrel sale clopidogrel 150mg pills

  59. Jdwaxw说道:

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

  60. Qcdwza说道:

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

  61. Erjjmc说道:

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

  62. Gnvymz说道:

    cost baclofen 10mg buy toradol cost ketorolac

  63. Xjbemn说道:

    order dilantin 100mg pills cost flexeril purchase oxybutynin generic

  64. Ognkcu说道:

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

  65. Dzvmvx说道:

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

  66. Jcqcqj说道:

    clomiphene pills purchase isosorbide generic order imuran 25mg for sale

  67. Gjcruf说道:

    symmetrel pill buy tenormin medication cost dapsone 100 mg

  68. Mpaznt说道:

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

  69. Ngmgpu说道:

    ladbrokes uk order stromectol generic generic stromectol for humans

  70. Rwnzye说道:

    cost protonix 40mg order pantoprazole 40mg pill pyridium pill

  71. Jhvgvi说道:

    play blackjack casino games online buy albuterol paypal albuterol pills

  72. Dbtduw说道:

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

  73. Wedoin说道:

    atorvastatin pills buy norvasc without prescription buy norvasc cheap

  74. Oktuyz说道:

    buy azithromycin 250mg online purchase prednisolone online cheap gabapentin generic

  75. Gamksk说道:

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

  76. Bjdkjy说道:

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

  77. Kguyjb说道:

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

  78. Xljepo说道:

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

  79. Kgsctz说道:

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

  80. Trusmp说道:

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

  81. Mzrsuz说道:

    order omeprazole 20mg for sale order generic singulair metoprolol pill

  82. Marafy说道:

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

  83. Omwnmu说道:

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

  84. Zlgman说道:

    zovirax order exelon pills purchase exelon generic

  85. Zpluar说道:

    order generic ferrous sulfate cheap sotalol 40mg buy sotalol online

  86. Didtpk说道:

    pyridostigmine ca piroxicam 20mg without prescription purchase maxalt online cheap

  87. Rzgejq说道:

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

  88. Iryval说道:

    etodolac 600 mg price order mebeverine generic cilostazol 100mg us

  89. Omxvvv说道:

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

  90. Fctawo说道:

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

  91. Qkbhiw说道:

    cost meloset danocrine 100mg usa danocrine 100mg cost

  92. Mmqngs说道:

    aspirin order brand aspirin zovirax over the counter

  93. Bqpucd说道:

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

  94. Cddpsn说道:

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

  95. Jgrahp说道:

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

  96. Upcvqx说道:

    tadalafil online viagra 50mg pills for men purchase viagra pill

  97. Gttwgr说道:

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

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

退出移动版