简体   繁体   English

MySQL内部连接查询给出错误

[英]MySQL Inner Join query giving errors

I have two Tables - char_items and items . 我有两个表 - char_itemsitems item_id is a common field among the two tables. item_id是两个表中的公共字段。

I want read the item_id from 'char_items' table and use that to obtain other information from the 'items' table based on that item_id. 我想从'char_items'表中读取item_id并使用它来根据item_id从'items'表中获取其他信息。 But my query is showing up as incorrect in MySQL. 但我的查询在MySQL中显示为不正确。 Please help -- 请帮忙 -

SELECT * FROM `char_items` WHERE char_id=$char_id && isSlotted=1 INNER JOIN `items` ON char_items.item_id=items.item_id

I keep getting the message: 我一直收到消息:

#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 `items` ON char_items.item_id=items.item_id

LIMIT 0, 30' at line 1 在第1行限制0,30'

Joins need to happen before the where clause 连接需要在where子句之前发生

SELECT * 
  FROM char_items c
 INNER 
  JOIN items i
    ON c.item_id = i.item_id
 WHERE char_id = $char_id 
   AND isSlotted = 1 

应该在join子句之后的位置,如下所示。

SELECT * FROM `char_items` INNER JOIN `items` ON char_items.item_id=items.item_id WHERE char_id=$char_id && isSlotted=1;

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

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