[英]SQL 'AS' statement Error in MySQL
I am trying to do the following sql to return 3 latest blog details from MySQL database, though getting the error, what I am missing here? 我试图做以下的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
I tried in the sql command window and its giving me the error as 我试过在sql命令窗口,它给我的错误为
#1064 - Erreur de syntaxe près de 'SUBSTR(post_content,1,23) FROM tblge_post ORDER BY tblge_post_id DESC LIMIT 3' à la ligne 1
#1064 - Erreur desyntaxeprèsde'SUBSTR(post_content,1,23)FROM tblge_post ORDER BY tblge_post_id DESC LIMIT3'Ãla ligne 1
and in the php I am trying the following code to display it, * all the mysql php retrieval objects are working fine. 并在PHP中我尝试以下代码来显示它,*所有的mysql php检索对象都正常工作。
$row['post_contentL']
Please help me to identify the problem. 请帮我确定问题所在。
It is the other way round. 反过来说。 Substitute this:
替换这个:
'post_contentL' AS SUBSTR(post_content,1,23)
with: 有:
SUBSTR(post_content,1,23) AS post_contentL
Alias
name should come after the Column
name. Alias
应该在Column
名后面。 You have reversed it 你扭转了它
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
it is not a valid query, Alias
should be named after query functions 它不是有效的查询,
Alias
应该在查询函数之后命名
'post_contentL' AS SUBSTR(post_content,1,23)
should be with 'AS' 应该与'AS'
SUBSTR(post_content,1,23) AS 'post_contentL'
OR without AS
或没有
AS
SUBSTR(post_content,1,23) 'post_contentL'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.