sql查询中的引号

时间:2011-09-30 11:13:32

标签: mysql

如果字段名称包含“ - ”或其他字符,或者字段具有“type”或其他字符的保留名称,如何在sql查询中添加引号

SELECT `enclosure.id`, `enclosure.time`, `enclosure.note` 
FROM tbl.enclosure LEFT JOIN tbl.book ON book.enc_id=enclosure.id 
WHERE `book.book_id`='277' ORDER BY enclosure.time DESC, enc_id_ DESC 

错误

#1054 - Unknown column 'enclosure.id' in 'field list'

2 个答案:

答案 0 :(得分:3)

我不确定我是否纠正你,但我认为你应该替换

`book.bookid`

`book`.`bookid`

答案 1 :(得分:0)

你在查询中有错误。它必须如下(你没有为表设置别名)

SELECT `enclosure`.id`, `enclosure`.time`, `enclosure`.note` 
FROM tbl_enclosure  enclosure 
LEFT JOIN tbl_book book ON `book`.`enc_id`=`enclosure`.`id` 
WHERE `book`.book_id`='277' 
ORDER BY `enclosure`.`time` DESC, `enclosure`.`enc_id` DESC