Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9024819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:07:12+00:00 2026-06-16T06:07:12+00:00

I’m trying to write a Union Query with multiple columns from two different talbes

  • 0

I’m trying to write a Union Query with multiple columns from two different talbes (duh), but for some reason the second column of the second Select statement isn’t showing up in the output. I don’t know if that painted the picture properly but here is my code:

Select empno, job
From EMP
Where job = 'MANAGER'
Union
  Select empno, empstate
  From EMPADDRESS
  Where empstate = 'NY'
  Order By empno

The output looks like:

EMPNO   JOB
4600    NY
5300    MANAGER
5300    NY
7566    MANAGER
7698    MANAGER
7782    MANAGER
7782    NY
7934    NY
9873    NY

Instead of 5300 and 7782 appearing twice, I thought empstate would appear next to job in the output. For all other empno‘s I thought the values in the fields would be (null). Am I not understanding Unions correctly, or is this how they are supposed to work?

Thanks for any help in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T06:07:14+00:00Added an answer on June 16, 2026 at 6:07 am

    If you want the data in a separate column you will want a JOIN not a UNION:

    Select e.empno, e.job, a.empstate
    From EMP e
    left join EMPADDRESS a
        on e.empno = a.empno
    Where job = 'MANAGER'
        AND empstate = 'NY'
    Order By e.empno
    

    A UNION combines the two results into a single set but the data is listed in the same columns. So basically they are placed on top of one another:

    select col1, col2, 'table1' as src
    from table1
    union all
    select col1, col2, 'table2' as src
    from table2
    

    Will result in:

    col1 | col2 | src
    t1   | t1   | table1
    t2   | t2   | table2
    

    If you want to have the data in a separate column which is sounds like you do then you will use a join of the tables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.