Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > need help on custom order by (dunno if this is the correct sub forum)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-09-08, 18:46
charaseac charaseac is offline
Registered User
 
Join Date: Oct 2008
Posts: 2
need help on custom order by (dunno if this is the correct sub forum)

Greetings!

im using oracle 9 and im using
JDBC connection for my application.

Basically this is what happens, i have this table called symbol, and in this i have a column called name.

My application right now do a search in the name.

For example, when user enters "micro" in the search box, the application will run a sql statement which will look into symbol table with name that contains "micro" in it. Then right now it is ordered alphabetically.

What i want to do is to order it in this way:
- names that start with the word the user search will be the first ones to appear
- and the rest will be sorted alphabetically

for example if user search for microsoft it will return something like

microsoft
micro virus
microworld
abe micro goods
trend micro AV

something like that.
Stumbled across order by case.. tried that, it doesnt work. Anyone can help me with this?

Thanks!
Reply With Quote
  #2 (permalink)  
Old 10-09-08, 19:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 13,539
Code:
ORDER BY CASE WHEN name LIKE 'micro%' THEN 0 ELSE 1 END , name
__________________
r937.com | rudy.ca

pre-order my book Simply SQL from Amazon
Reply With Quote
  #3 (permalink)  
Old 10-09-08, 19:51
charaseac charaseac is offline
Registered User
 
Join Date: Oct 2008
Posts: 2
Thanks

Thanks!

It worked beautifully, i just need to add upper(name) and it works with any upper/lower case combination

Thanks a lot!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On