Reputation: 339
I have two tables table1 and table2
In table1 i have two columns table1.userid and table2.full_name and in table2 i have two columns table2.userid and table2.ssn
I want records where userid present in both table1 and table2.
Records having userid present in table1 should be ignored if they are present in table2. If not present than want data from table1 also. Also want rest of the data from table2.
Should i use inner/outer/full join?
Can you please help me for the same.
Upvotes: 1
Views: 382
Reputation: 1269763
If you want userid
s that are present in both tables, then use inner join
:
select . . .
from table1 t1 inner join
table2 t2
on t1.userid = t2.userid;
If you want all the userid
s in table1
, then use left outer join
:
select . . .
from table1 t1 left outer join
table2 t2
on t1.userid = t2.userid;
If you want all the userids
s in both tables, then use full outer join
:
select . . .
from table1 t1 full outer join
table2 t2
on t1.userid = t2.userid;
Upvotes: 1