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 9132265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:16:56+00:00 2026-06-17T08:16:56+00:00

I have the following tables in a Hive database: table1: id t X 1

  • 0

I have the following tables in a Hive database:

table1:
id  t     X
1   1     a
1   4     a
2   5     a
3   10    a

table2:
id   t    Y
1    3    b
2    6    b
2    8    b
3    15   b

And I would like to merge them to have a table like:

id   t    Z
1    1    a
1    3    b
1    4    a
2    5    a
2    6    b
2    8    b
3    10   a
3    15   b

Basically what I want to do is :

  1. a join on the column id (that part is easy)

  2. merge the columns table1.t and table2.t into a new column t

  3. have the variable Z that is equal to table1.X if the corresponding t comes from table1.t, and table2.Y if it comes from table2.t

  4. order the table by id and then by t (that shouldn’t be too hard)

I have no idea on how to do the parts 2 and 3. I tried with an outer join on
table1.id = table2.id and table1.t = table2.t, but it doesn’t merge the two columns t.

Any pointer would be appreciated. Thanks!

  • 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-17T08:16:57+00:00Added an answer on June 17, 2026 at 8:16 am
    CREATE TABLE table3 as SELECT * FROM (SELECT id,t,X as Z FROM t3_1 UNION ALL SELECT id,t,Y as Z FROM t3_2) u1 order by id,t;
    

    Although not always required, using a subquery for the union’d queries help to organize, plus you can then reference the fields from the union (e.g. u1.id ) in other parts of the query.

    You’ll need the alias on the 3rd column to make the schemas match. If the source table name was not already a column, you could do something like this:

    select * from (select id,t,'a' from t3_1 UNION ALL select id,t,'b' from t3_2) u1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following two tables in the database. One table is person table and
I have following tables in my database: SuggestionsLog Table: ID, Title, Description. Employee Table:
Suppose that we have following tables create table Employee( 2 EMPNO NUMBER(3), 3 ENAME
I have the following tables in my database: Products ID_PRODUCT PRODUCTNAME PRICE Customers ID_CUSTOMER
I have the following tables. I want to run a query but I think
I have the following tables, with these keys in my database: bookings session_id sessions
I have the following tables in a database (i'll only list the important attributes):
For example if i have following tables in my database and Student and Course
I have following tables in my MySql database : +----------------------------------------------+ PROJECT +----------------------------------------------| +----------------------------------------------| project_id
I have Following Tables in SQL Server Database: (1) StudentMaster (StudentId, StudentName) (2) SubjectMaster

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.