简体   繁体   English

MYSQL-内部联接语法错误

[英]MYSQL - Inner Join Syntax Error

Yeah, little confused here. 是的,这里有点困惑。 I have number of tables in one of my wordpress installations and the name of them and the field names are pretty much descriptive. 我的其中一个wordpress安装中有很多表,它们的名称和字段名称几乎是描述性的。 So I don't think that you need any explanation for them. 因此,我认为您不需要为它们做任何解释。 My problem here is actually with the forth inner join I am trying to do. 我这里的问题实际上是我要执行的第四个内部联接。 The query is simple: 查询很简单:

SELECT * 
FROM wp_posts AS post 
    INNER JOIN wp_postmeta AS postmeta ON post.ID = postmeta.post_id 
    INNER JOIN wp_game AS game ON post.ID = game.post_id
    INNER JOIN wp_game_platform AS platform ON game.game_id = platform.GameId
    INNER JOIN wp_platform_release AS release ON release.PlatformID = platform.ID
WHERE post.post_type = 'games' AND postmeta.meta_key = 'post_views_count' AND platform.Status = 0 AND release.ReleaseDate > 1435917562
ORDER BY postmeta.meta_value DESC, game.game_id
LIMIT 100

This is supposed to get list of all the game platforms (Xbox version, PC version of a game) that are not released yet and sort them with their page visits. 可以获取尚未发布的所有游戏平台(Xbox版本,游戏的PC版本)列表,并按页面访问量对其进行排序。 As you can see the page visits are stored as post meta so I did a join on wp_postmeta. 如您所见,页面访问被存储为post meta,因此我对wp_postmeta进行了加入。 The above query gives me this syntax error: 上面的查询给了我这个语法错误:

failed : You have an error in your SQL syntax; 失败:您的SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release ON release.PlatformID = platform.ID WHERE post.post_type = 'games' AND ' at line 1 检查与您的MySQL服务器版本相对应的手册,以在'release ON release.PlatformID = platform.ID WHERE post.post_type ='games AND'的第1行附近使用正确的语法

Which clearly indicated that there is a syntax error in the query that I can't see. 这清楚地表明查询中存在语法错误,我看不到。 Funny enough if I run the following query, it returns the expected results (all the games [released or not] sorted by their post visits): 如果我运行以下查询,就很有趣了,它返回了预期的结果([发布或未发布的所有游戏]均按其访问后的时间排序):

SELECT * 
FROM wp_posts AS post 
    INNER JOIN wp_postmeta AS postmeta ON post.ID = postmeta.post_id 
    INNER JOIN wp_game AS game ON post.ID = game.post_id
    INNER JOIN wp_game_platform AS platform ON game.game_id = platform.GameId
WHERE post.post_type = 'games' AND postmeta.meta_key = 'post_views_count' AND platform.Status = 0
ORDER BY postmeta.meta_value DESC, game.game_id
LIMIT 100

At first I thought that there is a JOIN limit but after research I found out that the limit is more than 60 tables which is far from 5. So you see any thing that I can't? 一开始我以为有一个JOIN限制,但是经过研究,我发现该限制是超过60张表,而这与5张表相去甚远。所以,您看到我不能做的任何事情吗?

Thanks 谢谢

release is a reserved word - try changing the name of the alias to something else. release是保留字-尝试将别名更改为其他名称。 See : https://dev.mysql.com/doc/refman/5.0/en/keywords.html 参见: https : //dev.mysql.com/doc/refman/5.0/en/keywords.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM