Customized join output

ManasaPManasaP Registered User

Hi Everyone,

Example consider two tables Persons and Employee

Persons table sample:

Name,Address
1. john,new York
2. Diana,new jersey

Employee table sample:

Employee ID,Team
1. 123,developer
2. 568,tester

Required join Table output should be like

Name,Address,Employee ID,Team
1. john,new York,null,null
2. Diana,new jersey,null,null
3. null.null,123,developer
4. null,null,568,tester

I want above sample as output is there any way to solve this issue.help me please :)

Comments

  • Jim_KnicelyJim_Knicely Administrator, Moderator, Employee, Registered User, VerticaExpert

    Possible solution:

    dbadmin=> SELECT * FROM person;
     name  |  address
    -------+------------
     john  | new York
     Diana | new jersey
    (2 rows)
    
    dbadmin=> SELECT * FROM employee;
     ID  |   team
    -----+-----------
     123 | developer
     568 | tester
    (2 rows)
    
    dbadmin=> SELECT name "Name", address "Address", NULL "Employee ID", NULL "Team"
    dbadmin->   FROM person
    dbadmin->  UNION ALL
    dbadmin-> SELECT NULL, NULL, ID, team
    dbadmin->   FROM employee;
     Name  |  Address   | Employee ID |   Team
    -------+------------+-------------+-----------
     john  | new York   |             |
     Diana | new jersey |             |
           |            |         123 | developer
           |            |         568 | tester
    (4 rows)
    
  • ManasaPManasaP Registered User

    Thank u Mr.Jim Knicely :)

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file