急。。inner join 问题
select a.* from member_1 as a inner join tb_game_chat b on a.mem_id <> b.g_id where a.mem_type= '0 '
请问为什么不能用 <> 呢??结果是查询了多次
我想实现 查询表a不等于表b的
[解决办法]
用 <> 就相当于交叉联接
[解决办法]
你这个比较麻烦...
应该是先用inner join求出相等的
再求a 和 相等的集合的差集
[解决办法]
<> 的到的是乘积的查询
[解决办法]
select a.* ,b.g_id from member_1 as a inner join tb_game_chat b on (1=1) where a.mem_type= '0 ' and a.mem_id <> b.g_id
[解决办法]
not in 或者 not exists。例如:
select * from member_1 as a where mem_type= '0 ' and not exists(select * from tb_game_chat where g_id=a.mem_id)
[解决办法]
select a.* from member_1 as a inner join tb_game_chat b on a.mem_id <> b.g_id where a.mem_type= '0 '
-------------------------------------------
select * from member_1 where mem_id not in(select g_id from tb_game_chat) and mem_type= '0 '
用子查询不要用连接,虽然not in不是很好的方法可是也比用连接好一点