多表查询

1、两种方式
  1、select 字段名列表1,字段名列表2 from 表名列表,表名列表2; (笛卡尔积)
    1、记录多的表的每一条记录,去匹配另一张表的所有记录
    2、两张表的记录条数相同,则后表的每一条记录去匹配前表的所有的记录

    t1 : name -> "A1"  "A2"  "A3"
    t2 : name -> "B1"  "B2"
    select * from t1,t2;
    +------+-------+
    | name | name2 |
    +------+-------+
    | A1   | B1    |
    | A1   | B2    |
    | A2   | B1    |
    | A2   | B2    |
    | A3   | B1    |
    | A3   | B2    |
    +------+-------+

 

  2、... where 条件;

    示例:  

      select sheng.s_name as sheng,city.c_name as city,xian.x_name as xian from sheng,city,xian
      where
      sheng.s_id=city.cfather_id and
      city.c_id=xian.xfather_id;

 

posted on 2018-09-03 21:58  zengsf  阅读(162)  评论(0编辑  收藏  举报

导航