doumu5023 2016-10-20 05:31
浏览 81

mysql选择多个表并带回所有结果

I am trying to select everything from multiple tables where there are 2 conditions.

But they only bring back a single result from the second table, instead of everything

Here is the MySql code

SELECT *
  FROM `core_users`.`users`
     LEFT JOIN `core`.`orders`
       ON `core_users`.`users`.`uid` = `core`.`orders`.`uid`
     LEFT JOIN `core_users`.`crm`
       ON `core_users`.`users`.`uid` = `core_users`.`crm`.`uid`
  WHERE (`core_users`.`users`.`signup_timestamp` BETWEEN '1476626400' AND '1476712800'
     OR (`core_users`.`crm`.`type` = 'refresh_5in5' AND `core_users`.`crm`.`value` BETWEEN '1476626400' AND '1476712800') )

This just brings back 1 result from the crm table. However I want it to bring back all the results from the crm table.

How do I bring back everything from users, orders, and crm while having a WHERE clause on both tables?

  • 写回答

1条回答 默认 最新

  • douzhi8488 2016-10-20 05:39
    关注

    Try select users.*, orders.*, crm.*

    Please note that, in such case if you have common columns in any of these table like id in every table it would cause an ambiguous column name error. To get rid of that you need to specify these with alias name users.id as user_id, orders.id as order_id, crm.id as crm_id and so on.

    评论

报告相同问题?

悬赏问题

  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录