Mysql 使用商城表完成对商品信息的多表查询

### 使用商城表完成对商品信息的多表查询

#### 需求分析:

在商城项目中,我的订单中包含很多信息.打开订单需要去查询表

#### 技术分析:

#### 多表查询

- 交叉连接查询  笛卡尔积

- 内连接查询

- 左外连接

- 右外连接  

- 交叉连接查询  笛卡尔积
    select * from product;
    select * from category;

    --笛卡尔积  查出来的数据没有意义
    select * from product,category;

    查出有意义的数据
    select * from product as p,category as c where p.cno=c.cid;[使用as关键字]
    select * from product p,category c where p.cno=c.cid;[不使用as关键字]

- 内连接查询

    --隐式内连接
    select * from product p,category c where p.cno=c.cid;
    --显示内连接
    select * from product p inner join category c on p.cno=c.cid;

    --区别:
    隐示内连接:在查询出结果的基础上去做的where条件查询过滤
    显示内连接:带着条件去查询结果,执行效率很高

- 左外连接

select * from product p left outer join category c on p.cno=c.cid;


- 右外连接  

select * from product p right outer join category c on p.cno=c.cid;

猜你喜欢

转载自blog.csdn.net/mqingo/article/details/84678886