mysql查询wildness与从开发到生产的锂

时间:2012-02-14 10:51:07

标签: mysql syntax lithium

这是我的问题的要点..

 CREATE TABLE `customers` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
  `first_name` varchar(50) DEFAULT NULL,
  `last_name` varchar(50) DEFAULT NULL,
  `website` varchar(255) DEFAULT NULL,
  `chargify_customer_id` int(11) DEFAULT NULL,
  `source_url` varchar(255) DEFAULT NULL,
  `referer` varchar(255) DEFAULT NULL,
  `updated` datetime DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB; 


## This causes an error. 
mysql> SELECT Customers.id FROM `customers` AS `Customers` WHERE `Customers.chargify_customer_id` = xxx;
ERROR 1054 (42S22): Unknown column 'Customers.chargify_customer_id' in 'where clause'


## But
mysql> SELECT Customers.id FROM `customers` AS `Customers` WHERE `chargify_customer_id` = xxx ;

#gives a result

奇怪的是,我的mac开发环境,查询有效......也许,我只是需要睡觉而我错过了一些明显的东西?请帮助:)

1 个答案:

答案 0 :(得分:0)

你在这个和平的问题中引用

`Customers.chargify_customer_id`

让MySQL认为引号之间的孔字符串是列名。试试这个:

Customers.`chargify_customer_id`

你也可以这样做:

`Customers`.`chargify_customer_id`

因为这些单词不是保留的,所以你可以简单地留下引号并执行此操作:

Customers.chargify_customer_id