标签:size 多表 sql 0.00 sheng base values ase ble
【注】多表查询和连接查询(left join等) 功能类似,没有太大区别。
create database test charset utf8 collate utf8_bin;
use test;
create table tb_chengji(
xuesheng varchar(10) not null default ‘‘ primary key,
yuwen int(10)
)charset=utf8;
insert into tb_chengji values(‘亨德森‘,90),(‘拉拉纳‘,100),(‘马内‘,115),(‘库蒂尼奥‘,99);
create table tb_info(
id int(10) not null primary key auto_increment,
xuesheng varchar(10) not null default ‘‘,
xingbie char(1) not null default ‘‘,
dizhi varchar(10)select tb_info.id,tb_chengji.xuesheng,xingbie,dizhi,yuwen from tb_chengji,tb_info where tb_chengji.xuesheng=tb_info.xuesheng and tb_chengji.yuwen>=100; not null default ‘‘
)charset=utf8;
insert into tb_info values(1,‘马内‘,‘男‘,‘边锋‘),(2,‘库蒂尼奥‘,‘男‘,‘左中场‘),(3,‘拉拉纳‘,‘女‘,‘中场‘),(4,‘亨德森‘,‘女‘,‘后腰‘);
多表查询例子:
例子1
select tb_info.id,tb_chengji.xuesheng,xingbie,dizhi,yuwen from tb_chengji,tb_info where tb_chengji.xuesheng=tb_info.xuesheng and tb_chengji.yuwen>=100;
+----+-----------+---------+--------+-------+
| id | xuesheng | xingbie | dizhi | yuwen |
+----+-----------+---------+--------+-------+
| 1 | 马内 | 男 | 边锋 | 115 |
| 3 | 拉拉纳 | 女 | 中场 | 100 |
+----+-----------+---------+--------+-------+
2 rows in set (0.08 sec)
例子2
select tb_info.id,tb_chengji.xuesheng,xingbie,dizhi,yuwen from tb_chengji,tb_info where tb_chengji.yuwen>=100;
+----+-----------+---------+-----------+-------+
| id | xuesheng | xingbie | dizhi | yuwen |
+----+-----------+---------+-----------+-------+
| 1 | 拉拉纳 | 男 | 边锋 | 100 |
| 1 | 马内 | 男 | 边锋 | 115 |
| 2 | 拉拉纳 | 男 | 左中场 | 100 |
| 2 | 马内 | 男 | 左中场 | 115 |
| 3 | 拉拉纳 | 女 | 中场 | 100 |
| 3 | 马内 | 女 | 中场 | 115 |
| 4 | 拉拉纳 | 女 | 后腰 | 100 |
| 4 | 马内 | 女 | 后腰 | 115 |
+----+-----------+---------+-----------+-------+
8 rows in set (0.00 sec)
例1 tb_chengji.xuesheng=tb_info.xuesheng将表tb_chengji和tb_info连接起来,叫做等同连接。
例2 如果不使用tb_chengji.xuesheng=tb_info.xuesheng,那么产生的结果将是两个表的笛卡尔积,叫做全连接。
标签:size 多表 sql 0.00 sheng base values ase ble
原文地址:http://www.cnblogs.com/everest33Tong/p/5993806.html