【发布时间】:2013-12-22 09:54:12
【问题描述】:
我想根据datetime_lastactive 使用一个 SQL 查询从两个表中删除数据,并且如果 IP 地址与您自己的匹配。但是当我尝试以下 SQL 查询时收到此错误消息:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INNER JOIN visitors_main WHERE information_ipaddress = '123.123.123.123' A' at line 2' in ...
DELETE FROM visitors_list
INNER JOIN visitors_main
WHERE information_ipaddress = :ipaddress
AND datetime_lastactive < NOW() - INTERVAL 3 HOUR
表格如下所示:
CREATE TABLE IF NOT EXISTS `visitors_list` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`id_visitor` int(10) DEFAULT '0',
`id_user` int(10) DEFAULT '0',
`data_filename` text NOT NULL,
`data_filename_get` text NOT NULL,
`data_useragent` text NOT NULL,
`datetime_lastactive` datetime NOT NULL,
`information_ipaddress` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
)
CREATE TABLE IF NOT EXISTS `visitors_main` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`id_user` int(10) DEFAULT '0',
`data_coordinates` varchar(25) NOT NULL,
`datetime_firstvisit` datetime NOT NULL,
`checkbox_anonymous` tinyint(4) DEFAULT '0',
`checkbox_tiecoordinates` tinyint(4) DEFAULT '0',
`checkbox_nogps` tinyint(4) DEFAULT '0',
`information_ipaddress` text NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
)
我怎样才能做到这一点?
【问题讨论】:
-
尝试对表名使用反引号。
-
谢谢,但这并没有解决问题。我收到了同样的错误信息
-
在 WHERE 之前使用 ON 条件。
-
@Mihai
... ON information_ipaddress = :ipaddress WHERE ...?
标签: php sql inner-join