我有两个表 table1 和 table2
在 table1 我有两列 table1.userid 和 table2.full_name 在 table2 我有两列 table2.userid 和 table2.ssn
我想要 table1 和 table2 中都存在用户 ID 的记录。
如果 table2 中存在 userid 的记录,则应忽略它们。如果不存在,则还需要 table1 中的数据。还想要 table2 中的其余数据。
我应该使用内部/外部/完全联接吗?
你能帮我做同样的事情吗?
我有两个表 table1 和 table2
在 table1 我有两列 table1.userid 和 table2.full_name 在 table2 我有两列 table2.userid 和 table2.ssn
我想要 table1 和 table2 中都存在用户 ID 的记录。
如果 table2 中存在 userid 的记录,则应忽略它们。如果不存在,则还需要 table1 中的数据。还想要 table2 中的其余数据。
我应该使用内部/外部/完全联接吗?
你能帮我做同样的事情吗?
如果您想要两个表userid中都存在的 s,请使用:inner join
select . . .
from table1 t1 inner join
table2 t2
on t1.userid = t2.userid;
如果你想要所有的userids table1,那么使用left outer join:
select . . .
from table1 t1 left outer join
table2 t2
on t1.userid = t2.userid;
如果您想要两个表中的所有useridss,则使用full outer join:
select . . .
from table1 t1 full outer join
table2 t2
on t1.userid = t2.userid;