mysql - Apply SELECT LEFT() on the total characters from multiple columns combined -
i wanted limit characters retrieved mysql database , know left() function use. query
select id, left(heading, 80) heading, left(article, 20) article news order stamp desc limit 5;
but want limit total number of characters retrieved 'heading' , 'article' columns combined...
in other means; want total 100 chars both columns priority 'heading'... so, mr. sql, show 'heading' while can (within 100 chars range) , omit 'article' wish, if needed omit 'heading' reach 100 chars condition.
i.e. 'heading' gives 80 chars , 'article' gives 120 chars, therefore, delete 100 chars 'article'.
'heading' gives 110 chars , 'article' gives 500 chars, therefore, delete 500 chars article , 10 chars 'heading'
select id, left(heading, 100) heading, if(length(heading)>=100, '', left(article, 100-length(heading))) article news order stamp desc limit 5;
obviously if don't care having in 2 columns original query was, use concat
algorithm others mentionned.
Comments
Post a Comment