SQL – How To Retrieve Data With Maximum Length?

Suppose you have a schema called mySchema and a table called myTable. You would like to retrieve all data with maximum length (for instance, whose first name is the longest).

The following is a simple query to handle situations like this.

select  * from 
mySchema.myTable 
where length(myTable.firstName)=  
(select max(length(myTable.firstName))  
from mySchema.myTable

Simple Huh ! Well it sometimes saves you a minute. The functions are tested to work in DB2/AS-400

[My Video Promotion]
Tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.