1

当前的 SQL 查询在运行 MySQL 5.1.37 的 MAMP 1.8.4 上本地运行良好。

  SELECT 
    EL.log_actions, EL.log_date, EL.log_value, EL.log_type,    
    EA.admins_name, 
    EU.users_name, EU.users_matric
  FROM events_log EL
  JOIN events_users EU
    USING (users_id)          
  JOIN events_admins EA
    USING (admins_id)
  ORDER BY EL.log_id DESC
  LIMIT 0, 10

但是,当我将此查询实时带到运行 MySQL 4.1.22-standard 的生产服务器时,发生以下错误(条目中是否有数据)。

A Database Error Occurred

Error Number: 1054

Unknown column 'sceclub_exclaim2007.EU.admins_id' in 'on clause'

SELECT EL.log_actions, EL.log_date, EL.log_value, EL.log_type, 
EA.admins_name, EU.users_name, EU.users_matric 
FROM events_log EL 
JOIN events_users EU USING (users_id) 
JOIN events_admins EA USING (admins_id) 
ORDER BY EL.log_id 
DESC LIMIT 0, 20

这是基于 CodeIgniter 1.7.2 的,生产和开发都运行同一组数据库。

数据库表

events_users: users_id users_name users_credits 
  users_matric users_redeem

events_admins: admins_id admins_email admins_name 
  admins_pass admins_date admins_modified admins_last_login 

events_attendance: attendance_id users_id events_id

events_events: events_id events_name events_venue events_time 
  events_desc events_pass 

events_log:log_id admins_id log_actions log_date log_value 
  users_id log_type

我是 MySQL 的新手,所以我不知道版本有任何差异或可能是什么原因,提前谢谢你!

尝试谷歌搜索 MySQL4 的差异也无济于事。也尝试使用

  SELECT 
    EL.log_actions, EL.log_date, EL.log_value, EL.log_type,    
    EA.admins_name, 
    EU.users_name, EU.users_matric
  FROM events_log EL
  JOIN events_users EU
    where EL.users_id = EU.users_id
  JOIN events_admins EA
    USING EL.admins_id = EA.admins_id
  ORDER BY EL.log_id DESC
  LIMIT 0, 10

但是后来我在生产和开发中都遇到了错误。

发生数据库错误

错误号:1064

您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 8 行的“JOIN events_admins EA USING EL.admins_id = EA.admins_id ORDER BY”附近使用正确的语法

选择 EL.log_actions, EL.log_date, EL.log_value, EL.log_type, EA.admins_name, EU.users_name, EU.users_matric FROM events_log EL JOIN events_users EU where EL.users_id = EU.users_id JOIN events_admins EA USING EL.admins_id = EA.admins_id ORDER BY EL.log_id DESC LIMIT 0, 20

如果您可以向我指出一些资源,我可以在其中阅读有关 MySQL 4 语法的更多信息,以达到与 MySQL 5 语法相同的效果,请告诉我。

再次感谢!

4

2 回答 2

2
 SELECT 
    EL.log_actions, EL.log_date, EL.log_value, EL.log_type,    
    EA.admins_name, 
    EU.users_name, EU.users_matric
  FROM events_log AS EL
  JOIN events_users AS EU
    ON EL.users_id = EU.users_id
  JOIN events_admins EA
    ON EL.admins_id = EA.admins_id
  ORDER BY EL.log_id DESC
  LIMIT 0, 10
于 2010-03-20T21:41:01.507 回答
1

您尝试的第二个查询应该有关键字ON,不是USINGwhere

SELECT 
  EL.log_actions, EL.log_date, EL.log_value, EL.log_type,    
  EA.admins_name, 
  EU.users_name, EU.users_matric
FROM events_log EL
JOIN events_users EU
  ON EL.users_id = EU.users_id
JOIN events_admins EA
  ON EL.admins_id = EA.admins_id
ORDER BY EL.log_id DESC
LIMIT 0, 10

如果您仍然不确定是使用,还是,请查看JOIN的语法。WHEREONUSING

于 2010-03-20T21:42:56.903 回答