我收到以下错误:
SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'id' in field list is ambiguous
我不知道它来自哪里。堆栈跟踪也不清楚。抛出此错误的查询:
Database::executeQuery('CREATE TEMPORARY TABLE tmp_inventory ENGINE=MEMORY '
. 'SELECT id, email_hash, mailing_list_id, ttl, price, last_click, last_view, extra_data '
. 'FROM inventory i INNER JOIN mailing_list ml on i.mailing_list_id = ml.id '
. 'WHERE i.active = 0 AND i.deleted = 1 AND i.completely_deleted = 1 AND i.resting_to < NOW() AND i.next_sync_at < NOW() AND ml.active = 0 '
. 'LIMIT 10;');
所以我有两个表 - inventory和mailing_list。库存具有以下结构:
CREATE TABLE `inventory` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`email_hash` char(32) NOT NULL,
`mailing_list_id` int(6) DEFAULT NULL,
`created_at` datetime DEFAULT NULL,
`last_send_at` datetime DEFAULT NULL,
`resting_to` datetime DEFAULT NULL,
`next_sync_at` datetime DEFAULT NULL,
`ttl` datetime DEFAULT NULL,
`active` tinyint(1) NOT NULL DEFAULT '1',
`deleted` tinyint(1) NOT NULL DEFAULT '0',
`completely_deleted` tinyint(1) NOT NULL DEFAULT '0',
`price` int(10) unsigned NOT NULL,
`last_view` datetime DEFAULT NULL,
`last_view_at` datetime DEFAULT NULL,
`last_updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
)
和mailing_list:
CREATE TABLE `mailing_list` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) DEFAULT NULL,
`active` tinyint(1) NOT NULL DEFAULT '0',
`created_at` datetime NOT NULL,
`price` int(10) unsigned NOT NULL DEFAULT '1000',
`ttl` int(10) unsigned NOT NULL DEFAULT '604800',
`resting_time` int(10) unsigned NOT NULL DEFAULT '0',
`email_from` varchar(255) DEFAULT NULL,
`email_return_path` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
)
怎么了?
答案 0 :(得分:0)
在您的查询中,您正在访问FROM子句中的两个表:app.directive('contextmenuContainer', [function() {
return {
restrict: 'A',
scope: {},
link: function($scope, $element, $attrs, contextMenuCtrl) {
//if its there you can have code here
},
controller: function($scope) { //this must be here-
//the methods defined here will be exposed to the directive
//which inherits it using require.
$scope.open = function() {
//code here
};
//you could have other methods to.
}
}
}]);
,INNER JOIN子句中的inventory
。
这两个表都有一个名为mailing_list
的列,因此您的数据库不知道您所指的列。
要解决此问题,请在选择中指定表格,方法是将id
替换为id
或i.id