INNER JOIN语句出现SQL错误


SQL ERROR on INNER JOIN statement

我的sql查询出现以下错误。我一直在绞尽脑汁,似乎想不通。感谢您的帮助。

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查询:

// 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必须位于where 之前

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

由于可能两个表都有一个id列,我建议用au.id显式命名表。