Table1有u_name,Table2有u_name,u_type和u_admin
我想要的:使用Table1.u_name获取Table1.,Table2.u_admin,其中Table1.u_name=Tabl2.u_name和Table2.u_type='S‘。如果在Table2中没有这样的条目,我们仍然需要获取Table1。
请帮忙给我一些提示。非常感谢!
发布于 2010-05-25 19:01:48
我建议你阅读“外连接”,特别是“左外连接”,这就是你想要的。外部联接从一个表返回所有行,在没有匹配键的行的情况下,从联接表返回值的空值。
这两种方法都应该有效。
select table1.*, table2.u_admin from table1 left join table2
on table1.u_name=table2.u_name and table2.type='S'或
with a as (select u_name,u_admin from table2 where type='S')
select table1.*,a.u_admin from table1 left join a on table1.u_name=a.u_namehttps://stackoverflow.com/questions/2907623
复制相似问题