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?
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
#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
and in the php I am trying the following code to display it, * all the mysql php retrieval objects are working fine.
$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. 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
'post_contentL' AS SUBSTR(post_content,1,23)
should be with 'AS'
SUBSTR(post_content,1,23) AS 'post_contentL'
OR without AS
SUBSTR(post_content,1,23) 'post_contentL'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.