Skip to content
Advertisement

Select longest word from a string SQL

Let’s say that I have a table with 2 columns: name and number. Name is a string which can have one or more words and I would like a new query with select name number but that in the name column it only has the longest word of the original table.

Is there a function in SQL that extracts from a string only the longest word?

Advertisement

Answer

This procedure return the first longest word of the phrase pass like parameter.

To use it:

return: ‘three’ (because the longest words have 5 letters and this is the first of them)

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement