-1

我的 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;
4

1 回答 1

3

join必须先到 where

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

由于可能两个表都有一个id列,我建议用au.id.

于 2013-07-09T01:12:35.057 回答