table with multiple IDs but seperate notes need sorting (Tried SQL code to make a union query)

53 Views Asked by At

I have 2 tables, both with an ID and notes, these IDs and notes need blending, I do not know where to start with this, here is an example of what I have

TBL_1
ID    Info
1     Comment 1
2     Comment 2
3     Comment 3
4     Comment 4

TBL_2
ID    Info
2     Comment 5
4     Comment 6

and ideally what I would like is a query or a table that looks like this

ID    Info1        Info 2
1     Comment 1
2     Comment 2    Comment 5
3     Comment 3
4     Comment 4    Comment 6

Any sort of help or solution would be very appreciated

Thanks

P.s I messed around creating a union query using this code in SQL

SELECT TBL_1.[ID], TBL1.Info
FROM TBL_1
UNION ALL SELECT [TBL_2].ID, [TBL_2].[Info]
FROM TBL_1 INNER JOIN [TBL_2] ON TBL_1.[ID] = [TBL_2].ID;
1

There are 1 best solutions below

8
On BEST ANSWER

You don't need union, you need an outer join. Try this:

SELECT TBL_1.[ID], TBL_1.info, TBL_2.info As Info2
FROM TBL_1 
LEFT JOIN Tbl_2 ON(Tbl_1.[ID] = Tbl_2.[ID])

See fiddle here

Read here about different join types and when to use them.