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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:05:45+00:00 2026-06-05T08:05:45+00:00

I have two tables Table_A and Table_B and i want to join those tables

  • 0

I have two tables Table_A and Table_B and i want to join those tables to optain Table_c as the result:

Table_A:

+-----------+-----------+---------+
| tableA_id | tableB_id | v_id    |
+-----------+-----------+---------+
| 1         | 2         | 27      |
| 2         | 3         | 27      |
| 3         | 3         | 28      |
| 4         | 1         | 26      |
| 5         | 2         | 26      |
| 6         | 3         | 26      |
| 7         | 1         | 24      |
| 8         | 1         | 25      |
+-----------+-----------+---------+

Table_B:

+-----------+-----------+
| tableB_id | s_name    | 
+-----------+-----------+
| 1         | s1        |
| 2         | s2        | 
| 3         | s3        | 
+-----------+-----------+

Table_c:

+-----------+-----------+-----------++--------+
| tableB_id | s_name    | tableA_id | v_id    |
+-----------+-----------+-----------+---------+
| 1         | s1        | null      | null    |
| 2         | s2        | 1         | 27      | 
| 3         | s3        | 2         | 27      |
+-----------+-----------+-----------+---------+

I tried different queries, but i couldn’t reach the desired output.
This is MYSQL query: *Edit: reverse table order.

SELECT s.tableB_id, s.s_name, v.tableA_id, v.v_id
FROM Table_B  as s 
left OUTER JOIN Table_A  as v
ON v.v_id=27

EDIT:
The result should be all Table_B data on left and assign to it table_A data if any or make it null. How can i make this?

Last Edit:
Here is a solution i came up with:

SELECT s.tableB_id , s.s_name, v.tableA_id, v.v_id
FROM Table_B s , Table_A v
WHERE v.v_id=27 AND v.tableB_id = s.tableB_id 

UNION

SeLECT s.tableB_id , s.s_name, null as tableA_id, null as v_id
FROM Table_B s
WHERE s.tableB_id NOT IN (SELECT s.tableB_id 
FROM Table_B s , Table_A v
WHERE v.v_id=27 AND v.tableB_id = s.tableB_id )
  • 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-05T08:05:46+00:00Added an answer on June 5, 2026 at 8:05 am

    You could try:

    SELECT tb.tableB_id, tb.s_name, ta.tableA_id, ta.v_id
    FROM Table_B tb LEFT JOIN Table_A ta
      ON tb.tableB_id = ta.tableB_id
    

    To choose only one you could use:

    SELECT tb.tableB_id, tb.s_name, ta.tableA_id, ta.v_id
    FROM Table_B tb LEFT JOIN 
    (SELECT * FROM Table_A 
     WHERE v_id = 27) ta
      ON tb.tableB_id = ta.tableB_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables that I need to join... I want to join table1
I have two tables which I want to connect. TABLE_A: +-----------+-----------+---------+ | row_id |
I have two tables TABLE_A and TABLE_B having the joined column as the employee
I have two tables (Table A and Table B) which I want to join
I have two tables, Table_A and Table_B. Table_A has a one-to-many relationship with Table_B.
I have two tables that I want to join into one table and use
I have two tables (Table A, Table B) joined with a join table (TableAB)
I have two tables TableA aId aValue TableB bId aId bValue I want to
I have two tables that I need to join. These are: art id |
I have two CSV files with a common column and I want to Join

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.