4

I don't understand why this didn't work out:

select id,name,concat(substring(description,0,30),'...') as desc_shortened, created_date,added_by from products

Even though there is data inside of the description field. I didn't see any field example on mySQL documentation tho. They used pure strings instead of column names.

concat(susbtring(description,0,30)) only returns ... and that's all.

2 Answers 2

8

Use substring(description,1,30) instead.

Sign up to request clarification or add additional context in comments.

2 Comments

I didn't know it starts with 1. I was hoping it would start with 0 . It is always like this?
depends on the language, and even on type. Strings in VB start with 0, Collections with 1 (with a dummy 0 inserted on creation)
0

Oracle treat 0 as 1 in this function, but mysql treat 0 as empty.So you should use substring(description,1,30).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.