sql中查询两个表时其中一个表的数据为10条,而另一个表的数据为5条,怎么能用查询命令显示完全呢?

sql中查询两个表时其中一个表的数据为10条,而另一个表的数据为5条,怎么能用查询命令显示完全呢
我用的查询命令是
select a.item_no,a.stock_qty,b.pos_qty from A a,B b
where a.item_no=b.item_no
但这样查询只查出条件相等的5条记录,而其他的显示不出来
请问用查询命令显示完全呢

第1个回答  推荐于2016-07-01
select a.item_no,a.stock_qty,b.pos_qty from A
full join b on a.item_no=b.item_no追问

但查询带有聚合函数就不行了!请帮忙解决一下!
select a.bm,a.mc,count(b.auto_flag) from zfl a full join t_bd_item_info b

on a.bm=left(b.item_clsno,4) and b.status<'4'and b.item_no=c.item_no
group by a.bm,a.mc
order by a.bm;

追答

--你这个情况用left join比较好
select a.bm,a.mc,count(b.auto_flag)
from zfl a
left join t_bd_item_info b
on a.bm=left(b.item_clsno,4) and b.status<'4' and b.item_no=c.item_no
group by a.bm,a.mc
order by a.bm;

追问

运行不了!提示错误!“在关键字‘group’附近有语法错误。Contiue”

追答

b.item_no=c.item_no
这个C表哪里来的,是不是应该改为a.

追问

这是完整的查询,请帮忙看一下哪里错了!谢谢
select a.bm,a.mc,count(b.auto_flag),count(c.branch_no) from zfl a left join t_bd_item_info b left join t_im_branch_stock c

本回答被提问者和网友采纳
相似回答