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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:23:27+00:00 2026-06-18T04:23:27+00:00

I have three tables table1, table2 and table 3. I am getting data to

  • 0

I have three tables table1, table2 and table 3. I am getting data to a file with sequence of the output as shown below. I want to append the data coming in that file to a table4 that ill create and persist using Java.

Scenario: I want all the data in this three tables into one cloumn where table2 element matches table3 element in C4 then instead of that matched element i want to replace that element with the corresponding data in C5. For example in below mentioned table we see 11 in table2 matches table3 at column C4. Then the output should have 11_1, 11_2 instead of 11.

Help needed

Table1:                  Table2:                          Table3:

C1                       C3                               C4        C5
-----                    ------                           ------    -------
1                        11                               11        11_1
2                        12                               11        11_2
3                        13                               14        14_1
4                        14                               14        14_2
5                        15                               14        14_3
                         16                               null      null 

Code I worked:

SELECT c1 
FROM   (SELECT c1 
        FROM   table1 
        UNION ALL 
        SELECT c3 
        FROM   table2 
        UNION ALL 
        SELECT c5 
        FROM   table3) temp 

This query fetching me everything 🙁

SELECT C1 FROM(SELECT DISTINCT C1 AS C1 FROM table1 UNION ALL SELECT DISTINCT C2 FROM table2)AS 
temp LEFT JOIN table3 ON .temp.C1=table3.C4 CASE WHEN table3.C4=NULL THEN temp.C1 ELSE table3.C5

Output Required:

Table4
C1
-----
1
2
3
4
5
11_1
11_2
12
13
14_1
14_2
14_3
15
16

Help is appreciated

  • 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-18T04:23:28+00:00Added an answer on June 18, 2026 at 4:23 am

    This should work:

    SELECT col 
    FROM   (SELECT c1 AS col 
            FROM   table1 
            UNION ALL 
            SELECT CASE 
                     WHEN t3.c4 IS NULL THEN t2.c3 
                     ELSE t3.c5 
                   end AS col 
            FROM   table2 t2 
                   LEFT JOIN table3 t3 
                          ON t3.c4 = t2.c3) temp 
    

    Result

    |  COL |
    --------
    |    1 |
    |    2 |
    |    3 |
    |    4 |
    |    5 |
    | 11_1 |
    | 11_2 |
    |   12 |
    |   13 |
    | 14_1 |
    | 14_2 |
    | 14_3 |
    |   15 |
    |   16 |

    See the demo

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

Sidebar

Related Questions

I have three tables of data: table: cars [10,000 rows] table: planes [2,000 rows]
I want to append data of two tables in a resultset. I have tried
Say I have three tables: Fruit (Table 1) ------ Apple Orange Pear Banana Produce
I have three tables. The designs were like student table create table student (studID
I have a database with three tables: user_table country_table city_table I want to write
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three tables, Name - columns Custpackingslipjour(table 1) - (deliverydate, dateclosed,, salesid) Inventrans
I have three tables Author, Book and AuthorBook. AuthorBook table only contains two foreign
I have three mysql table from same database Db1. Three tables have following columns.
I have three tables Category, Movies and RelCatMov Category-table categoryid, categoryName 1 thriller 2

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.