[英]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.