由于某些原因,在执行以下查询时出现以下错误:
您的SQL语法有误。检查手册
对应于您的MySQL服务器版本以使用正确的语法
第35行的“ ENGINE = FEDERATED”附近
CREATE TABLE users AS (
SELECT
ID, user_email, user_registered,
first_name.meta_value as first_name,
last_name.meta_value as last_name,
telephone.meta_value as telephone,
country.meta_value as country,
company.meta_value as company,
address.meta_value as address,
city.meta_value as city,
professional_title.meta_value as professional_title,
state.meta_value as state,
areas_of_interest.meta_value as areas_of_interest
FROM wp_users
LEFT JOIN wp_usermeta AS first_name ON first_name.user_id=ID
AND first_name.meta_key='first_name'
LEFT JOIN wp_usermeta AS last_name ON last_name.user_id=ID
AND last_name.meta_key='last_name'
LEFT JOIN wp_usermeta AS telephone ON telephone.user_id=ID
AND telephone.meta_key='telephone'
LEFT JOIN wp_usermeta AS country ON country.user_id=ID
AND country.meta_key='country'
LEFT JOIN wp_usermeta AS company ON company.user_id=ID
AND company.meta_key='company'
LEFT JOIN wp_usermeta AS address ON address.user_id=ID
AND address.meta_key='address'
LEFT JOIN wp_usermeta AS city ON city.user_id=ID
AND city.meta_key='city'
LEFT JOIN wp_usermeta AS professional_title ON professional_title.user_id=ID
AND professional_title.meta_key='professional_title'
LEFT JOIN wp_usermeta AS state ON state.user_id=ID
AND state.meta_key='state'
LEFT JOIN wp_usermeta AS areas_of_interest ON areas_of_interest.user_id=ID
AND areas_of_interest.meta_key='areas_of_interest'
) ENGINE=FEDERATED DEFAULT CHARSET=latin1 CONNECTION "*****";
注意:FEDERATED Engine已打开并且正在其他非联接表上工作。
最佳答案
简短答案:
FEDERATED表的CREATE语句需要另外一条称为CONNECTION的数据。语句中没有该数据是语法错误的根源。
长答案:
对于此特定实例,与FEDERATED表相比,VIEW是更好的工具。
FEDERATED存储引擎可以有点像Linux中的符号链接或Windows中的快捷方式。它主要用于访问服务器上的表,该服务器实际上不在本地存储表,而是在其他mysql服务器上。因此,在创建FEDERATED表时,还必须在CREATE语句中包括FEDERATED存储引擎应使用的CONNECTION。您可以选择在存储数据的同一主机上创建FEDERATED表,但是由于不必要的访问本地数据的步骤,将导致额外的开销。有关更多详细信息,请参见this link。
另一方面,VIEW就像存储的查询一样,只要您查询VIEW表,它就会执行。 This page可以为您提供更多信息。
关于mysql - 两个LEFT JOIN表的联合表不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26931034/