is there a way to make a join like that?

59 Views Asked by At

I have to table first one

type nbD
PC 2

second one

type nbF
PC 3
TAB 2

and I want to have something like that

type nbD nbF
PC 2 3
TAB null 2
2

There are 2 best solutions below

1
On BEST ANSWER

You can achieve using below query.

Moreover, before asking for help from community, do some research of your own. I believe if you would have searched "SQL joins with example" in google, you would have get this in first or second result. By that way you learn more, and if you get stuck in the process then you have always have the option to ask for help.

Select a.type, b.ndb, a.ndf
from tab2 a 
left join tab1 b on a.type = b.type
0
On

What you want to use here is a FULL OUTER JOIN:

SELECT st.type_, ft.nbd, st.nbf
FROM second_table st
FULL OUTER JOIN first_table ft ON ft.type_ = st.type_;

OUTPUT:

type_ nbd  nbf
----- ---  ---
PC    2    3
TAB   null 2

Feel free to refer to this DB Fiddle to check it yourself :)