简体   繁体   English

在SQL查询中定义ORDER

[英]Define ORDER in sql query

I'm having trouble getting my sql to pull in photos based on the column "order" which contains numbers. 我无法让我的SQL根据包含数字的“订单”列提取照片。 The following works fine, however it seems to be pulling in photos based on the "num" column in "cms_uploads". 以下工作正常,但是似乎是基于“ cms_uploads”中的“ num”列提取照片。

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

This query returns nothing: 该查询不返回任何内容:

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

order is a reserved word . order保留字

You need backticks rather than single quotes for the order by . 您需要反引号而不是单引号来order by You are ordering by a constant -- that is, doing nothing: 您正在按常数排序-即不执行任何操作:

ORDER BY `order`

To help with writing code, only use single quotes for string constants and dates. 为了帮助编写代码, 仅对字符串常量和日期使用单引号。

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

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