zoukankan      html  css  js  c++  java
  • mysql:联合查询

    SELECT t1.name, t2.salary  FROM employee AS t1 INNER JOIN info AS t2 ON t1.name = t2.name; 可以对数据表使用别名

    select t1.id,t2.id
    from t1
    left join t2 on t1.id = t2.id and t1.id>1 and t2.id<>3

    http://wenku.baidu.com/link?url=r-ks3kd0ZtGJtLW9vKq_B7kAEJtugvPaCV1NMitCesHi1DJWip50P44R6Ck076bDFyyKw1caIKpPyLP5yWympLGoqP25QHJN2A0sKHyhKLe

    在mysql的left join中条件放在on后面和在where后面是不同的;

    1. on后面只针对于t2表进行过滤,所以上面的t1.id>1将不起作用,切记,切记;

    2. where后面会对最终结果产生影响,所以如果t2.id<>3放到on后面和where后面也是会返回不同的结果;

      例如下面脚本一会比脚本二多返回一些数据。

    http://database.51cto.com/art/201011/234480.htm

    select * from test2
    left join test1 on test2.id = test1.id and test1.id<>3
    where test2.id <>6;
    select * from test2
    left join test1 on test2.id = test1.id
    where test2.id <>6 and test1.id<>3;
  • 相关阅读:
    Python Challenge 第十二关
    Python Challenge 第十一关
    Python Challenge 第十关
    Python Challenge 第九关
    Python Challenge 第八关
    Python Challenge 第七关
    zepto
    zepto
    zepto
    zepto
  • 原文地址:https://www.cnblogs.com/kxdblog/p/4046410.html
Copyright © 2011-2022 走看看