This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes sql query regarding order Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "sql query regarding order" Watch "sql query regarding order" New topic
Author

sql query regarding order

swapnil kataria
Ranch Hand

Joined: Feb 26, 2011
Posts: 64
please see the query

SELECT * FROM EMP_LIST WHERE
NAME LIKE '%RAHUL%' OR
NAME LIKE '%SMITH%' OR
NAME LIKE '%SANJANA%' OR
NAME LIKE '%AMIT%' ;

when i run this query, it is retrieving records fine, but it is not coming in proper order,

i means, i want records mathcing 'RAHUL' should come first, and then records matching 'SMITH' should come second and so on,

is there any way to handle order is such a way, please help
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19911
    
  23

How about SQL's ORDER BY clause?

I'll move this thread to our JDBC forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

In a simple SQL query using the "ORDER BY" clause will result in alphabetically ordered records. However, it will not order as you have specified.


S.D. MADHAN
Not many get the right opportunity !
 
rocket mass heater kickstarter
 
subject: sql query regarding order