zoukankan      html  css  js  c++  java
  • SQL多表查询

    设置主键:点击右键设为主键,在默认值那设置newid(),即可自动生成

    Join

    inner join(内连接):select * from 表1 inner join 表2 on 表1.列 = 表2.列  //inner join与 join是相同的,把两表中相同的数据列出来

    left join(左连接):select * from 表1 left join 表2 on 表1.列 = 表2.列  //以左表为主(全部列出来),右表与左表相关的数据列出来

    right join(左连接):select * from 表1 right join 表2 on 表1.列 = 表2.列  //以右表为主(全部列出来),左表与右表相关的数据列出来

    full join(左连接):select * from 表1 full join 表2 on 表1.列 = 表2.列  //列出两表所有数据,左表与右表相关的数据合一起

    Alias别名

    select 表1别名.列,表1别名.列, 表2别名.列 from 表1 as 表1别名, 表2 as 表2别名 where 表1.列 = 表2.列   //表别名
    select 列 as 别名,列 as 别名 from 表名称    //列别名

    union:用于合并两个或多个 SELECT 语句的结果集,只选取不同的值  //union内部的 sekect语句必须拥有相同数量的列。列也必须拥有相似的数据类型。 select 列 from 表1 union select 列 from 表2

    union all:允许重复的值

    select into:从一个表中选取数据,然后把数据插入另一个表中  //select * into 新表 from 表名称

    create database:创建数据库  //create database 数据库名

  • 相关阅读:
    bae问题
    union intersect minus
    在搭建SpringMvc Hibernate框架时遇到的问题
    详细解读Spring2.5 +Struts1.3 框架(使用Spring声明式事物管理和springjjdbc模板)
    javaee缓存技术 oscache ehcache
    Warning
    Math
    Test
    网络流24题-最小路径覆盖问题
    Wannafly summer camp Day3--Knight
  • 原文地址:https://www.cnblogs.com/sctnl/p/6046624.html
Copyright © 2011-2022 走看看