메뉴 닫기

SQL UNION Clause

  • UNION combines the result sets of two queries.
  • Column data types in the two queries must match.
  • UNION combines by column position rather than column name.

The definitive guide
for data professionals
Order today! 
  See 2 min video

The SQL UNION syntax

The general syntax is:

  1. SELECT columnnames
  2. FROM tablename
  3. UNION
  4. SELECT columnnames
  5. FROM tablename

SQL UNION Examples

Problem: List all contacts, i.e., suppliers and customers.

  1. SELECT ‘Customer’ As Type,
  2. FirstName + ‘ ‘ + LastName AS ContactName,
  3. City, Country, Phone
  4. FROM Customer
  5. UNION
  6. SELECT ‘Supplier’,
  7. ContactName, City, Country, Phone
  8. FROM Supplier

This is a simple example in which the table alias would be useful
Results:

Type ContactName City Country Phone
Customer Alejandra Camino Madrid Spain (91) 745 6200
Customer Alexander Feuer Leipzig Germany 0342-023176
Customer Ana Trujillo México D.F. Mexico (5) 555-4729
Customer Anabela Domingues Sao Paulo Brazil (11) 555-2167
Supplier Anne Heikkonen Lappeenranta Finland (953) 10956
Supplier Antonio del Valle Saavedra Oviedo Spain (98) 598 76 54
Supplier Beate Vileid Sandvika Norway (0)2-953010
Supplier Carlos Diaz Sao Paulo Brazil (11) 555 4640
Supplier Chandra Leka Singapore Singapore 555-8787
Supplier Chantal Goulet Ste-Hyacinthe Canada (514) 555-2955
Supplier Charlotte Cooper London UK (171) 555-2222

33 Comments

  1. g by

    Wonderful items from you, man. I’ve remember your stuff prior to and you’re simply too great.
    I really like what you have acquired here, certainly
    like what you’re saying and the way by which you assert it.
    You make it enjoyable and you still care for to keep it sensible.
    I can’t wait to read far more from you. This is actually a tremendous site.

  2. https://tinyurl.com/rsacwgxy g

    Fantastic website you have here but I was curious
    if you knew of any discussion boards that cover the same topics
    discussed here? I’d really like to be a part of community where I can get feed-back from
    other experienced people that share the same interest. If you have any suggestions, please let me
    know. Appreciate it!

  3. http://tinyurl.com/y8byulpw

    I have been exploring for a little bit for any high-quality articles
    or weblog posts in this sort of area . Exploring in Yahoo I eventually stumbled upon this website.
    Studying this info So i’m glad to express that I have an incredibly excellent uncanny feeling I
    discovered exactly what I needed. I so much undoubtedly will
    make certain to don?t omit this web site and give it a glance regularly.

  4. Zola Westin

    I simply want to mention I’m all new to blogging and definitely savored this web blog. Likely I’m planning to bookmark your site . You certainly have tremendous posts. Many thanks for revealing your web page.

  5. buy viagra direct from pfizer

    I?m pleased, I have to state. Actually seldom do I experience a blog that?s both instructional and enjoyable, as well as let me inform you, you have actually hit the nail on the head. Your idea is impressive; the concern is something that not nearly enough individuals are speaking smartly around. I am extremely happy that I stumbled across this in my search for something connecting to this.

  6. cbd oil for sale without thc

    There are certainly a lot of details like that to take into account. That is an excellent point to bring up. I supply the thoughts over as general motivation but clearly there are inquiries like the one you bring up where the most important thing will certainly be working in straightforward good faith. I don?t recognize if ideal techniques have emerged around points like that, but I make sure that your work is clearly determined as a level playing field. Both kids as well as women feel the effect of just a moment?s satisfaction, for the remainder of their lives.

  7. Tractor Workshop Manuals

    My spouse and i got very thankful when Peter could finish off his reports through your ideas he grabbed from your blog. It is now and again perplexing to simply choose to be giving for free steps that many most people might have been selling. We consider we’ve got you to thank for that. Most of the explanations you’ve made, the easy website menu, the friendships your site make it possible to foster – it’s many fantastic, and it’s really assisting our son and us believe that the matter is thrilling, and that is particularly pressing. Thank you for all!

  8. look at more info

    An impressive share, I just given this onto a colleague that was doing a little analysis on this. As well as he actually purchased me morning meal because I located it for him. smile. So let me reword that: Thnx for the treat! However yeah Thnkx for investing the moment to review this, I really feel highly concerning it and love finding out more on this topic. Ideally, as you become expertise, would certainly you mind upgrading your blog site with even more information? It is very helpful for me. Big thumb up for this post!

  9. safest cbd capsules

    When I originally commented I clicked the -Alert me when brand-new remarks are added- checkbox and also now each time a remark is included I obtain 4 e-mails with the very same comment. Is there any way you can remove me from that service? Many thanks!

  10. Website

    Hello there! I simply would love to provide a huge thumbs up for the fantastic info you have below on this message. I will certainly be coming back to your blog for more quickly.

  11. more information

    Can I just claim what an alleviation to discover somebody that actually recognizes what theyre talking about on the web. You definitely recognize how to bring a concern to light as well as make it important. More people need to read this as well as understand this side of the tale. I angle think youre not much more prominent since you definitely have the gift.

  12. cheap flights to florida round trip

    Greetings from Colorado! I’m bored to tears at work so I decided to
    browse your website on my iphone during lunch break.
    I enjoy the info you present here and can’t wait to take a look
    when I get home. I’m surprised at how fast your blog loaded on my cell phone ..
    I’m not even using WIFI, just 3G .. Anyways, great blog!

  13. talks about it

    Aw, this was a truly great post. In suggestion I would love to place in writing such as this in addition? requiring time and also actual initiative to make a very good article? however what can I state? I postpone alot as well as never appear to obtain something done.

  14. inquiry

    Hey there! I just wish to provide a substantial thumbs up for the excellent information you have below on this message. I will certainly be coming back to your blog for even more quickly.

댓글 남기기

이메일은 공개되지 않습니다.