我正在尝试使用特定列(使用JOIN)从同一个数据库中的两个表中提取结果,然后按两个表之一中的特定列进行排序。问题出在我的声明的后半部分 - 我没有看到如何指定我想要排序的表和列。
SELECT * FROM general_assessment INNER JOIN location_info USING (general_id) ORDER FROM location_info BY timestamp desc limit 0,1
我似乎无法使ORDER
部分的语法正确。我知道我不能只指定ORDER BY
,因为如果不首先指定表格,它将是不明确的。我该怎么做ORDER BY表和我想要的列?
错误讯息:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 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 'FROM location_info BY timestamp desc limit 0,1' at line 1' in C:\wamp\www\Dropbox\pip\testing\tim\results.php on line 22
答案 0 :(得分:0)
答案很简单,并没有要求" ORDER或FROM"只需加入.
SELECT * FROM general_assessment INNER JOIN location_info USING (general_id) ORDER BY location_info.timestamp desc limit 0,1";