Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I want to join 2 table to become 1 table
My Table :
1. tbl_Item
2. tbl_conversion

tbl_Item Fields is :
1. Item_Code
2. Item_Name

tbl_conversion Fields is :
1. Conversion_Id
2. Item_Code1
3. Qty1
4. Item_Code2
4. Qty2

So, what I want to do is I want to take Item_Name from tbl_Item and merge that to tbl_conversion

The result I want is Like This :
| Conversion_Id | Item_Code1 | Item_Name1 | Qty1 | Item_Code2 | Item_Name2 | Qty2|

What I have tried:

I've tried some JOIN variation, but I can't get the result I want. .
Posted
Updated 11-Apr-23 22:27pm

JOIN is the correct approach:
Joins (SQL Server) - SQL Server | Microsoft Learn[^]

You haven't explained what you have tried, nor what the problem is. At a guess, try:
SQL
SELECT
    C.Conversion_Id,
    C.Item_Code1,
    I1.Item_Name As Item_Name1,
    C.Qty1,
    C.Item_Code2,
    I2.Item_Name As Item_Name2,
    C.Qty2
FROM
    tbl_Conversion As C
    INNER JOIN tbl_Item As I1 ON I1.Item_Code = C.Item_Code1
    INNER JOIN tbl_Item As I2 ON I2.Item_Code = C.Item_Code2
;
If the columns can contain Null, or your foreign key relationship is not set up properly, you may need to use LEFT JOIN instead of INNER JOIN.
 
Share this answer
 
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900