File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Searching and matching keyword Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Searching and matching keyword" Watch "Searching and matching keyword" New topic
Author

Searching and matching keyword

yigit darcin
Greenhorn

Joined: Jan 08, 2008
Posts: 15
Hello All,

I am using Postgres Db and I have this following problem:

My requirement is getting all the results based on the keyword but, the results should be ascending based on matching the keyword

For example I have this Number_Prefix table:

id prefix priority
1 90212 1
2 90212 2
3 90216 1
4 9021 1
5 9021 2
6 90 1

when I make a select with keyword = '90212' on prefix column, what I want to see is :

1 90212 1
2 90212 2
4 9021 1
5 9021 2
6 90 1

or I make a select with keyword = '9021' on prefix column, what I want to see is :

4 9021 1
5 9021 2
6 90 1

so the query will look for 9021 then 902 and 90 and so on.

can this be done in one single sql call?

thanks in advance.

Yigit
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

Not sure, but try.


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30085
    
149

Yigit,
The order part is easy "order by keyword desc, priority".

For the rest of it, I think you'd need a stored procedure to do it in one call - looping by substring.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Searching and matching keyword
 
Similar Threads
Inner and Outer Joins
Nested Loops
related links query
SCBCD - 90%
converting ascii number to capital letter