我已经做了一些搜索,并根据这里的例子和其他在线资源多次重新处理我的sql,但每次运行此sql时,我都会得到相同的“#1064-您的sql语法有错误”错误。
我正在尝试使用内部连接连接四个表,它们应该始终有匹配的数据来进行键关闭(即,对于每个有效的令牌/token\u id,应该始终有一整行)。我使用的是MySQL5.7.26版本,下面是我尝试运行的查询:
SELECT
i.name AS invitee_name,
c.first_name AS child_first,
c.last_name AS child_last,
s.invite_status,
c.avatar
FROM
Invites AS i, Tokens AS t, Children AS c, Invite_Statuses AS s
WHERE
t.token = sdie02d
INNER JOIN
t ON t.token_id = i.token_id
INNER JOIN
c ON c.child_id = i.child_id
INNER JOIN
s ON s.status_id = i.status_id
我(每次)收到的全部错误是:
# 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
t ON t.token_id = i.token_id
INNER JOIN
c ON c.child_id ' at line 11
表格如下所示:
Invites
+---------+----------+----------+-----------+---------------+----------+
| user_id | child_id | token_id | status_id | email | name |
+---------+----------+----------+-----------+---------------+----------+
| 9 | 2 | 1 | 1 | a@example.com | John Doe |
| 9 | 3 | 2 | 1 | b@example.com | Jane Doe |
+---------+----------+----------+-----------+---------------+----------+
Tokens
+----------+---------+
| token_id | token |
+----------+---------+
| 1 | 93kd8i0 |
| 2 | sdie02d |
| 3 | fsj2d9c |
+----------+---------+
Children
+----------+------------+-----------+--------+
| child_id | first_name | last_name | avatar |
+----------+------------+-----------+--------+
| 1 | Timmy | Johnson | 4 |
| 2 | Jenny | Smith | 32 |
| 3 | Jake | Jones | 12 |
+----------+------------+-----------+--------+
Invite_Statuses
+-----------+---------------+
| status_id | invite_status |
+-----------+---------------+
| 1 | invited |
| 2 | accepted |
| 3 | rejected |
+-----------+---------------+
谢谢你的帮助。
3条答案
按热度按时间kqqjbcuj1#
此处出现多个错误
rsl1atfo2#
看看其他内部连接的例子,试着把where语句放在末尾,看看是否有效?
https://www.mysqltutorial.org/mysql-inner-join.aspx/
n3ipq98p3#
需要在where子句条件“qme34j”中添加“”