views:

95

answers:

2

I have the most simple SQL

SELECT * FROM words

It has 13000 words (varchar). I need to get the longest word first in my output. I guess it might be possible with the WHERE command?

Alternative

If it doesn't work like that, is there a smart way to sort my output array so it will order it by the longest word first (in the 'word'-column). It looks like this (in the output loop)?

$output_array[$row['word']] = $row['another_word'];
+3  A: 

Ordering the words by its length should do it:

SELECT *
FROM words
ORDER BY LENGTH(word) DESC
Gumbo
Will that work even though VARCHAR is padded to a given length?
Adrian Schmidt
@Adrian Schmidt: What do you mean by padded?
Gumbo
@Adrian Schmidt: CHAR is padded, VARCHAR isn't.
R. Bemrose
@Adrian Schmidt: varchars are not padded, chars are.
klausbyskov
Of course... I must have had a brain melt... haha
Adrian Schmidt
A: 
select * from words order by len(my_field) desc;
tomk