Darshan Darshan - 2 months ago 7
SQL Question

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?

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.

Answer

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
Comments