在sql 中据说使用,
exists 效率高于in,那么exists 跟in等价的sql如下,
aa跟bb表关联字段user_id
select * from aa where aa.user_id not in (select bb.user_id from bb);
select * from aa where not exists(select bb.user_id from bb where bb.user_id=aa.user_id);
select * from aa where aa.user_id in (select bb.user_id from bb);
select * from aa where exists(select bb.user_id from bb where bb.user_id=aa.user_id);
使用union 跟union all :
他们都可以关联多个表,不同的是:
union 会对查询的字段依据字段先后进行排序,去掉重复值。而union all 则不会去重复跟排序
SELECT USER_ID, USER_NAME FROM AA
UNION
SELECT USER_ID, USER_NAME FROM BB
;
SELECT USER_ID, USER_NAME FROM AA
UNION ALL
SELECT USER_ID, USER_NAME FROM BB
;
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net