LeoSam
LeoSam

Reputation: 4951

postgres query count characters and order by longest length

I'm using the following query to print all title from stories table

select title from stories;

which show me all titles , The point here how to tweak it and do the following :

`order by longest title or even count longest title` 

any tips

Upvotes: 21

Views: 26331

Answers (1)

user sflskjdf
user sflskjdf

Reputation: 554

If you to order by the length of the title (longest to shortest) you should use the following query

select title from stories order by length(title) desc

Upvotes: 51

Related Questions