繁体   English   中英

MySQL中的SQL'AS'语句错误

[英]SQL 'AS' statement Error in MySQL

我试图做以下的sql从MySQL数据库返回3个最新的博客详细信息,虽然得到错误,我在这里缺少什么?

SELECT   tblpost_id, 
         post_title, 
         img_url, 
         img_date, 
         post_catg, 
         'post_contentL' AS substr(post_content,1,23) 
FROM     tblpost 
ORDER BY tblpost_id DESC 
LIMIT    3

我试过在sql命令窗口,它给我的错误为

#1064 - Erreur desyntaxeprèsde'SUBSTR(post_content,1,23)FROM tblge_post ORDER BY tblge_post_id DESC LIMIT3'Ãla ligne 1

并在PHP中我尝试以下代码来显示它,*所有的mysql php检索对象都正常工作。

$row['post_contentL']

请帮我确定问题所在。

反过来说。 替换这个:

'post_contentL' AS SUBSTR(post_content,1,23)

有:

SUBSTR(post_content,1,23) AS post_contentL

Alias应该在Column名后面。 扭转了

SELECT tblpost_id, 
       post_title, 
       img_url, 
       img_date, 
       post_catg, 
       Substr(post_content, 1, 23) AS `post_contentL` --here 
FROM   tblpost 
ORDER  BY tblpost_id DESC 
LIMIT  3 

它不是有效的查询, Alias应该在查询函数之后命名

'post_contentL' AS SUBSTR(post_content,1,23) 

应该与'AS'

SUBSTR(post_content,1,23) AS 'post_contentL'

或没有AS

SUBSTR(post_content,1,23) 'post_contentL'

暂无
暂无

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

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