在sql查询中定义ORDER

时间:2014-01-15 19:13:20

标签: php mysql sql

我无法让我的sql根据包含数字的“订单”列来提取照片。以下工作正常,但它似乎是基于“cms_uploads”中的“num”列拉入照片。

$photoSql = "SELECT * FROM cms_uploads WHERE ('tableName'='residential_master_rental_availabilities' AND 'recordNum' = '".$rent['num']."' AND 'fieldname' = 'image') LIMIT 1";

此查询不返回任何内容:

$photoSql = "SELECT * FROM cms_uploads WHERE ('tableName'='residential_master_rental_availabilities' AND 'recordNum' = '".$rent['num']."' AND 'fieldname' = 'image') ORDER BY 'order' LIMIT 1";

1 个答案:

答案 0 :(得分:3)

orderreserved word

order by需要反引号而不是单引号。你是按常数排序 - 即什么也不做:

ORDER BY `order`

为了帮助编写代码,使用单引号作为字符串常量和日期。