Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2004, 02:30 AM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Order recordsets by relevancy

I have an SQL string that does a search using

SELECT * WHERE Titlename LIKE '%Crimson%' AND Titlename LIKE '%Skies%' order BY Titlename

This gives me all results containing both "Crimson" and "Skies". But I want a result that contains exactly "Crimson Skies" to appear first in addition to the blended results. Any idea how?


 
Old June 8th, 2004, 02:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Then this may help you.

Code:
SELECT * WHERE Titlename LIKE '%Crimson Skies%' or (Titlename NOT LIKE '%Crimson Skies%' and LIKE '%Crimson%Skies%') order BY Titlename
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 8th, 2004, 03:42 AM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmmm, still doesn't work, as exact matches for "Crimson Skies" are still not at the top. I'm not quite sure what your logic was for this query, so if you can explain it, maybe that'll kick-start something in my brain. Thanks!

 
Old June 8th, 2004, 03:50 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Hi,

 you can try thr following query:

SELECT * WHERE Titlename LIKE '%Crimson Skies%' order BY Titlename


Om Prakash
 
Old June 9th, 2004, 12:27 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Kafer,
Then you will have to split that in to two queries and use UNION Operator.

Code:
SELECT * WHERE Titlename LIKE '%Crimson Skies%'
SELECT * WHERE Titlename LIKE Titlename NOT LIKE '%Crimson Skies%' and LIKE '%Crimson%Skies%'
UNION ALL
order BY Titlename
Use the Order by Clause if required, because this would again collapes the order in which you want it to be displayed.

Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 9th, 2004, 03:02 AM
Registered User
 
Join Date: Jun 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, the best solution I found so far is

SELECT Titlename, 1 as rank WHERE Titlename like '%Crimson Skies%' group by Titlename order by 1
UNION
SELECT Titlename, 2 as rank WHERE Titlename LIKE '%Crimson%' AND Titlename LIKE '%Skies%' group by Titlename order by 2

But this gives me duplicates. Any idea how to get rid of the dupes?

 
Old June 9th, 2004, 03:09 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Code:
Select distinct Title from
(
SELECT Titlename, 1 as rank WHERE Titlename like '%Crimson Skies%' group by Titlename order by 1 
UNION 
SELECT Titlename, 2 as rank WHERE Titlename LIKE '%Crimson%' AND Titlename LIKE '%Skies%'  group by Titlename order by 2 
)
Does that help?
Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordsets JezLisle Access VBA 11 July 17th, 2007 03:47 AM
Help with Recordsets voskoue Access VBA 1 January 23rd, 2007 08:36 AM
Need help with recordsets chacquard Access VBA 5 June 21st, 2004 11:58 PM
Recordsets bph Access VBA 17 February 17th, 2004 03:19 PM
document node order vs sort node order. ladyslipper98201 XSLT 2 June 5th, 2003 11:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.