mysql - 从 2 个表中选择。 MySql

标签 mysql sql mysql-error-1054

如何在不输入长全名的情况下选择 p.Quota?现在我正在做

SELECT c.id, 
       c.UserName, 
       p.Quota, 
       cs.StatusName 
  FROM CUSTOMERS AS c, 
       PRODUCTS AS p 
 LEFT JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId=cs.CustomerStatusId 
 LIMIT 1 ;

我得到错误:

ERROR 1054 (42S22): Unknown column 'c.StatusId' in 'on clause'

但是该列确实退出并且此代码有效:

SELECT c.id, 
       c.UserName, 
       cs.StatusName 
  FROM CUSTOMERS AS c
  JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId = cs.CustomerStatusId 
 LIMIT 1 ;

最佳答案

您正在混合使用 ANSI 和非 ANSI JOIN 语法:

SELECT c.id, 
       c.UserName, 
       p.Quota, 
       cs.StatusName 
  FROM CUSTOMERS AS c, 
       PRODUCTS AS p 
  LEFT JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId=cs.CustomerStatusId 
  LIMIT 1 ;

使用 ANSI 连接编写:

     SELECT c.id, 
            c.UserName, 
            p.Quota, 
            cs.StatusName 
       FROM CUSTOMERS AS c 
       JOIN PRODUCTS AS p ON --JOIN criteria goes here
  LEFT JOIN CUSTOMERSTATUSTYPES as cs ON c.StatusId = cs.CustomerStatusId 
      LIMIT 1;

...但我不知道您使用什么标准将 PRODUCTS 加入 CUSTOMERS 表。

关于mysql - 从 2 个表中选择。 MySql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1478080/

相关文章:

MYSQL从表中获取尚未过去的最后日期

5.0.12 更改后的 MySQL LEFT JOIN - 如何重写查询

mysql - 对抗 INNER JOINS - Chapter : unknown column

mysql - 如何向具有 GROUP BY 和 HAVING 子句的查询再添加一个连接?

php - 在 mySQL 列中存储随机大小的数组

mysql - 使 MySQL 可以远程访问,安装在 Windows PC 上

javascript - 监听表并在发生变化时调用函数

mysql - 使用 SQL 查询总和

mysql - 通用 Mysql 存储过程

mysql - 选择那些有多个条目的字段