Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Join all record even not match

I have tables_1 and table_2

table_1

id   name   cost
100  joe     10
101  bob     20
102  mary    30

table_2

id   name
100  joe 
101  bob
102  mary
103  tom

I want to join these tables even no match id and expect result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

id   name   cost
100  joe    10
101  bob    20
102  mary   30
103  tom    null 

My query

select t1.id, t1.name, t1.column1, t1.column2
from Table_1 t1
join Table_1 t2 on t1.id = t2.id
and  t1.id <> t2.id 

I got nothing return. Need some help. Thank you

>Solution :

What you need is a right join (or a left join if you reverse the order of tables in the join)

select table_2.id, table_2.name, table_1.cost
from table_1 right join table_2
on table_1.id = table_2.id
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading