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. | +-------------------+----------+------------------------+
lasix canada doxycycline 100mg without prescription albuterol inhalator generic
buy escitalopram 10mg without prescription revia 50mg for sale buy naltrexone 50 mg sale
cost strattera 10mg buy atomoxetine generic purchase sertraline online
buy zithromax online neurontin 800mg pills purchase gabapentin online
actigall for sale order cetirizine 5mg generic order zyrtec 10mg generic
buy deltasone generic accutane 40mg usa where can i buy amoxil
strongest prescription antacid heartburn pills over the counter burping medication australia
get estrogen prescription online how to naturally last longer stronger ejaculation pills
promethazine sale where to buy ed pills without a prescription buy stromectol
non bleeding erosive gastropathy biopsied medication foe errosive gastritis over the counter urinary tract infection meds
purchase duloxetine sale modafinil cost order provigil generic
anti fungal tablets for skin abruptly stopping blood pressure medication high blood pressure medicine list
cyproheptadine for sale cyproheptadine 4mg brand order nizoral 200mg pills
buy herpes treatment online ordering valtrex overnight delivery drugs to treat prediabete
brand medroxyprogesterone medroxyprogesterone ca buy hydrochlorothiazide without a prescription
new medications for smoking cessation best prescription to stop smoking buy pain pills online usa
letrozole 2.5mg generic cost abilify order aripiprazole 30mg online cheap
where to buy zopiclone pills sleeping pills non prescription uk virtual weight loss clinic
where to buy minocin without a prescription minocin 100mg drug buy requip 2mg
order alfuzosin 10 mg pill buy alfuzosin 10 mg sale best medicine for heartburn relief
buy generic clonidine over the counter buy generic tiotropium for sale order generic tiotropium bromide 9 mcg
get acne pills online best pimple medication for teenagers buy oxcarbazepine medication
amoxicillin 250mg us arimidex tablet biaxin order
buy calcitriol 0.25 mg pill order fenofibrate sale buy tricor 200mg online cheap
academic writing services uk dissertation in accounting suprax oral
academic writing best real money casino free roulette games
aspirin 75 mg ca order aspirin 75 mg online blackjack online real money
buy trazodone 100mg buy trazodone 100mg generic clindac a order
purchase tadacip for sale tadalafil 20mg usa indocin pill
brand ceftin buy ceftin online cheap robaxin 500mg pills
retin cream brand avanafil 200mg brand avana online order
buy tamoxifen no prescription buy symbicort for sale purchase budesonide
order generic cleocin order generic erythromycin 500mg order sildenafil 50mg pills
lamotrigine 50mg canada buy generic lamotrigine 200mg buy vermox 100mg online cheap
metronidazole cheap flagyl medication buy cephalexin 500mg generic
buy aurogra generic cost aurogra 50mg estradiol order
fluconazole 200mg usa acillin pills baycip brand
oral spironolactone 100mg propecia order brand propecia 1mg
order motilium 10mg without prescription buy coreg cheap generic sumycin 250mg
tamsulosin usa ondansetron 4mg cheap buy simvastatin for sale
buy buspirone 5mg online cordarone 100mg over the counter order amiodarone 200mg pill
ranitidine 150mg over the counter zantac ca order celecoxib 200mg pill
allopurinol 300mg generic buy rosuvastatin without a prescription crestor 10mg cheap
order imitrex 50mg generic buy dutasteride generic buy generic avodart
buy azelastine sprayer order acyclovir 400mg pills purchase irbesartan generic
order esomeprazole 20mg capsules order mirtazapine 30mg for sale topiramate canada
buy pepcid 40mg generic buy prograf no prescription tacrolimus brand
buy glimepiride 1mg online cheap purchase cytotec arcoxia order
buy pamelor order nortriptyline 25 mg without prescription cost acetaminophen 500mg
order inderal 20mg sale clopidogrel sale clopidogrel 150mg pills
fosamax 70mg over the counter buy fosamax paypal furadantin 100 mg ca
order baclofen 10mg online order ozobax online cheap toradol without prescription
loratadine 10mg pill buy tritace without a prescription dapoxetine 60mg sale
cost baclofen 10mg buy toradol cost ketorolac
order dilantin 100mg pills cost flexeril purchase oxybutynin generic
buy generic vardenafil 20mg order digoxin without prescription buy tizanidine without a prescription
medrol 8 mg without prescription brand aristocort buy triamcinolone 10mg generic
clomiphene pills purchase isosorbide generic order imuran 25mg for sale
symmetrel pill buy tenormin medication cost dapsone 100 mg
online blackjack live dealer buy augmentin 375mg generic cheap synthroid 100mcg
ladbrokes uk order stromectol generic generic stromectol for humans
cost protonix 40mg order pantoprazole 40mg pill pyridium pill
play blackjack casino games online buy albuterol paypal albuterol pills
online casino slots no download blackjack for money buy lasix 100mg
atorvastatin pills buy norvasc without prescription buy norvasc cheap
buy azithromycin 250mg online purchase prednisolone online cheap gabapentin generic
purchase cefdinir without prescription buy lansoprazole 30mg online buy prevacid 30mg pills
accutane 40mg sale buy azithromycin 250mg buy zithromax 500mg pills
buy provigil 200mg for sale order provigil 100mg generic order prednisone 10mg without prescription
order generic cenforce 50mg order aralen 250mg pills order chloroquine 250mg online cheap
buy telmisartan 20mg for sale buy molnupiravir 200mg sale molnupiravir 200 mg ca
buy tadalafil 10mg pills cialis 40mg over the counter order viagra 50mg
order omeprazole 20mg for sale order generic singulair metoprolol pill
buy premarin 0.625mg sale purchase sildenafil sale sildenafil 100mg for sale
buy vasotec 5mg pills purchase doxazosin sale buy cheap generic duphalac
zovirax order exelon pills purchase exelon generic
order generic ferrous sulfate cheap sotalol 40mg buy sotalol online
pyridostigmine ca piroxicam 20mg without prescription purchase maxalt online cheap
order florinef online cheap order loperamide 2 mg online buy imodium online cheap
etodolac 600 mg price order mebeverine generic cilostazol 100mg us
buy dydrogesterone 10mg generic jardiance 25mg for sale generic empagliflozin 25mg
buy dipyridamole online buy plendil 5mg sale pravastatin 10mg usa
cost meloset danocrine 100mg usa danocrine 100mg cost
aspirin order brand aspirin zovirax over the counter
purchase precose sale generic repaglinide 2mg order griseofulvin 250 mg pills
buy generic minoxidil over the counter order mintop online buy ed pills gb
buy zaditor 1mg pills ketotifen uk imipramine 25mg for sale
tadalafil online viagra 50mg pills for men purchase viagra pill
buy tricor 160mg online cheap tricor cost order fenofibrate 160mg sale