数据检索-多表查询(sybase)

数据检索-多表查询
chinayaosir 12/22/2008

//1.single select sentence
//1.单表查询
//1.1 single select sentence with table i_itembasic,then run value is TotalRows:12695
//primary key is itemnumber
select count(*) as TotalRows
from i_itembasic;
/*
run value:
TotalRows
12695
*/

//1.2 single select sentence with table i_itembasic_bab,then run value is TotalRows:12634
//primary key is itemnumber
select count(*) as TotalRows
from i_itembasic_bab;
/*
run value:
TotalRows
12634
*/

//2.inner join select sentence(select * form table1,table2...)
//2.内连接
select count(*) as TotalRows
from      i_itembasic,i_itembasic_bab
where  i_itembasic.itemnumber = i_itembasic_bab.itemnumber;



//3.outer join
//3.外连接

//3.a right outer join select sentence(=*)
//3.a 右外连接
//3.a.1 primary table choose i_itembasic_bab,slave table choose i_itembasic
select count(*) as TotalRows
from      i_itembasic,i_itembasic_bab
where  i_itembasic.itemnumber =* i_itembasic_bab.itemnumber;
/*
run value:
TotalRows
12634
*/

//3.a.2 primary table choose i_itembasic,slave table choose i_itembasic_bab
select count(*) as TotalRows
from      i_itembasic,i_itembasic_bab
where  i_itembasic_bab.itemnumber =* i_itembasic.itemnumber ;
/*
run value:
TotalRows
12695
*/

/*
why?3.a.1(TotalRows:12634) <>3.a.2(TotalRows:12695)
pls thinking...
then study right outer join with www.google.cn or www.baidu.com
then you can see
*/

//3.b left outer join select sentence(*=)
//3.b 左外连接
//3.b.1 primary table choose i_itembasic,slave table choose i_itembasic_bab
select count(*) as TotalRows
from      i_itembasic,i_itembasic_bab
where  i_itembasic.itemnumber *= i_itembasic_bab.itemnumber;
/*
run value:
TotalRows
12659
*/

//3.b.2 primary table choose i_itembasic_bab,slave table choose i_itembasic
select count(*) as TotalRows
from     i_itembasic,i_itembasic_bab
where  i_itembasic_bab.itemnumber *= i_itembasic.itemnumber ;
/*
run value:
TotalRows
12634
*/

/*
why?3.b.1(TotalRows:12695) <>3.b.2(TotalRows:12634)
pls thinking...
then study left outer join with www.google.cn or www.baidu.com
then you can see
*/

//4.cross select sentence(=)
//交叉查询两表之间的笛卡尔乘积
select count(*) as TotalRows
from      i_itembasic,i_itembasic_bab
where  i_itembasic.itemnumber = i_itembasic_bab.itemnumber;

/*
run value:
TotalRows
12632
*/

/*
why ?12632 <>12695<>12634
pls thinking...
then study left outer join with www.google.cn or www.baidu.com
then you can see
*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值