SQL Basics

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsDatabasesSQL Basics

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old January 22nd, 2013, 03:59 PM
Madde Madde is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 Madde User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 18 m 32 sec
Reputation Power: 0
Find the longest text in sql

hi everyone :]

i'm trying to find the longest text in my column row DNAME. i have succeded in doing so but i cant seem to show the longest text only the ammout of length.

SELECT MAX(CHAR_LENGTH(DNAME)) as 'Max length'
FROM DEPT;


this will give the answer

+------------+
| max length |
+------------+
| 10 |
+------------+


what i want to show is

+--------------+--------------+
| DNAME | Max LENGTH |
+--------------+--------------+
| ACCOUNTING | 10 |
+--------------+--------------
i tried with:

SELECT DNAME, MAX(CHAR_LENGTH(DNAME)) as 'Max length'
FROM DEPT HAVING MAX(CHAR_LENGTH(DNAME));


(this will only give the first DNAME in the column row, not the one with the longest length and the max length totally in the column row)

and

SELECT DNAME as 'Max length'
FROM DEPT HAVING MAX(CHAR_LENGTH(DNAME));


(this wil only give the first DNAME in the column row and not the one with the longest length)

I'm using putty :]
would appreciate any answer :]

Reply With Quote
  #2  
Old January 24th, 2013, 08:27 AM
vignesh56 vignesh56 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 1 vignesh56 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 11 sec
Reputation Power: 0
Sql

SELECT DISTINCT DNAME,
LENGTH(DNAME) as "Max Length"
FROM DEPT
WHERE LENGTH(DNAME)=
(SELECT MAX(LENGTH(DNAME)) FROM DEPT
)

Try this n tell me...

Regards,
Vignesh L

Reply With Quote
Reply

Viewing: Tutorialized ForumsDatabasesSQL Basics > Find the longest text in sql


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap