標籤: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,那麼產生的結果將是兩個表的笛卡爾積,叫做全串連。
mysql多表查詢例子