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

    有2个表,一个表里面必须另外一个表的uuid(主键),sql语句写的时候,

    要写成:select  t.name,s.* from `jxc_contacts` t,`jxc_customer` s where  t.target_id=s.uuid (where  t.target_id=s.uuid这个条件的前提就是在 t表中,必须要有s表的uuid,不然查询不到,t.target_id=s.uuid,t里面有他自己的uuid,t里面有target_id,这个target_id是s里面的uuid,其实意思就是,target_id的值,必须要和s表里面的Uuid要一样)

    刚刚又更新了,我现在是3张表查询,但是我有2张表都有同样的Name,然后可以在 t.name后面再给他一个别名tname,要记得加上一个as 这样,他就不会重复了。

    select  t.name as tname,s.*,f.name as fname from `jxc_contacts` t,`jxc_customer` s,jxc_attachment f where  t.target_id=s.uuid and f.`target_id`=s.`uuid` 

  • 相关阅读:
    第五次作业
    第四次作业
    第三次作业
    第二次作业
    第一次作业
    实验三 算术编码压缩方法
    实验二 统计压缩方法的具体实现
    实验一 建立统计压缩方法理论模型
    第五次作业
    第四次作业
  • 原文地址:https://www.cnblogs.com/likeji/p/6277169.html
Copyright © 2011-2022 走看看