zoukankan      html  css  js  c++  java
  • SQL多个表实现联合查询

    select LineId,Id,Country from Domestic
    union all
    select LineId,Id,Country from Freedom
    -- 联合查询Domestic,Freedom表的LineId,Id,Country all代表不去除反复
    --功能:[SQL语句] UNION [SQL语句]将两个语句中选择的同一列中的不同的值筛选出来

    SELECT<表1>.<列名> ,<表2><列名>FROM<表1>OUTER JOIN<表2> ON<表1>.<列>=表2>.<列名>
    --功能:实现两个表的外连接

    Select Domestic.LineId,Freedom.LineId from Domestic,Freedom where Domestic.Sames=Freedom.Sames
    Select Domestic.LineId,Freedom.LineId FROM Domestic inner join Freedom on Freedom.Sames=Domestic.Sames
    --功能:实现两个表的内连接 把Domestic,Freedom两个表用Domestic.Sames=Freedom.Sames关联起来显示Domestic.LineId,Freedom.LineId
    ------------------------
    我的数据库表是这种:table0101,table0102,table0103,.......各个表有同样的结构,我想用sql语句从查询分析器里导出来,有沒有办法能够一次导出,语句要返回一个结果集.
    用union all就能够实现:

    select * from table0101
    union all
    select * from table0102
    union all
    select * from table0103
    union all
    select * from table0104
    ....

    ****************
    补充:假设想去掉反复记录的话,把union all 改成 union就能够了
    ---
    以上,希望对你有所帮助。

  • 相关阅读:
    3月9号作业
    7、循环之while循环和深浅copy
    6、可变不可变类型和运算符以及流程控制之if判断
    5、垃圾回收机制与用户交互以及运算符
    作业3月5号
    3月4号作业
    4、语法之变量以及基本数据类型
    3、Python介绍
    2、计算机基础详解
    五、流程控制值if...else
  • 原文地址:https://www.cnblogs.com/mfryf/p/3437466.html
Copyright © 2011-2022 走看看