0

I've two tables which have following columns:

ERD

Now I want have a SQL query which gives me an output as follows: SQL output

I wrote already some SQL code, but this doesn't work because the union operator needs the same number of columns with the same type. Have a look.

SELECT *
FROM
(SELECT User_tbl1.Username, User_tbl1.Surname, User_tbl1.Givename
FROM User_tbl1
UNION
SELECT User_tbl2.User_PK
FROM User_tbl2)

Can someone help me to bring my SQL query working, so that it will output a hyphen at surname and givename if the record is located in table "User_tbl2"?

Thanks a lot!

1
  • 1
    Your UNION clause is totally wrong... Post some sample data and ur desired output. Commented Mar 2, 2012 at 14:36

1 Answer 1

5

As simple as:

SELECT User_tbl1.Username, User_tbl1.Surname, User_tbl1.Givename
FROM User_tbl1
UNION
SELECT User_tbl2.User_PK, '-', '-'
FROM User_tbl2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.