简体   繁体   English

对INNER JOIN语句的SQL错误

[英]SQL ERROR on INNER JOIN statement

I have the following error below for my sql query. 我的SQL查询出现以下错误。 I have been racking my head and can't seem to figure it out. 我一直在绞尽脑汁,似乎无法弄清楚。 Any help is appreciated. 任何帮助表示赞赏。

Error:
08-07-2013, 19:05:55: Database access error. Please contact the site administrator. SELECT * FROM realty_auctions WHERE id = 42962 INNER JOIN realty_agents ON realty_auctions.agentsid=realty_agents.agentsid; 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 realty_agents ON realty_auctions.agentsid=realty_agents.age' at line 3 page:/home/propoint/public_html/item.php line:567

SQL Query: SQL查询:

// get agent data
$query = "SELECT * FROM " realty_auctions WHERE id = " . $id ." INNER JOIN realty_agents ON " realty_auctions.agentsid=realty_agents.agentsid; ";
$result = mysql_query($query);
$system->check_mysql($result, $query, __LINE__, __FILE__);
$agent_data = mysql_fetch_assoc($result);
echo $agent_data;

join must come before where join必须在where之前

SELECT * 
FROM realty_auctions au
INNER JOIN realty_agents ag ON au.agentsid = ag.agentsid
WHERE au.id = $id 

And since probably both tables have an id column I suggest naming the table explicitly with au.id . 由于两个表都可能有一个id列,因此我建议使用au.id显式命名该表。

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

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