2 messages in com.mysql.lists.mysqlRe: Sorting by relevance
FromSent OnAttachments
CU-Jobs17 Jun 1999 06:56 
Christian Mack17 Jun 1999 11:03 
Subject:Re: Sorting by relevance
From:Christian Mack (Ma@compal.de)
Date:06/17/1999 11:03:45 AM
List:com.mysql.lists.mysql

CU-Jobs wrote:

Hello,

I am trying to sort a result set based on the columns it was matched on but not
having much luck.

I have two fields in a database, say "movietitle" char(80) and "description"
which is a blob.

If I search on "Star Wars" I'd like all the entries match "Start Wars" in the
title listed first and ones that only have it match it in the description listed
second.

How can one do this with one SQL statement?

Hi John

Try: SELECT movietitle , IF( LOCATE( 'Star Wars', movietitle), 1, 2 ) AS preferred FROM movies WHERE movietitle like '%Star Wars%' OR description like '%Star Wars%' ORDER BY preffered

I also would suggest to use TEXT instead of BLOB for 'description', because with
TEXT you have case insensitive search capabilities as in CHAR or VARCHAR.

Tschau Christian