0

Hi,

How do i order results for most relevant one?

Select id, title from data where (titleLIKE '%PHP developer%')

id title
---- -------------------------------
1 ASP developer
2 WEB developer
3 PHP
4 PHP developer

In this case, it should be displayed in this other 4, 3, 2, 1 OR 4, 3, 1, 2

Thanks

5
Contributors
7
Replies
8
Views
8 Years
Discussion Span
Last Post by veledrom
0

Are you sure your query returns ASP developer/WEB developer/PHP when you use LIKE '%PHP developer%' :S This, infact should return only "PHP developer".

0

What is the definition of relevant ? If you use the LIKE clause, you will get only those records in which the filed contains the content of the LIKE clause. So if you have all records containing the content you want, I don't think you can order them by any means.

0

Let's say a texbox has "PHP, ASP, developer, programmer, web developer, Java"

What SQL statement could be be for me to use to return results?

Thanks

0

Explode the textbox value. Then use the exploded values to
1. build your query this way.

where title like '%PHP%' or title like '%ASP%' or title like '%developer%' or title like '%programmer%' or title like '%web developer%' or title like '%Java%'

2. Or you can have different queries for every exploded value.

select * from table where title like %PHP%';
select * from table where title like '%ASP%';
....etc...

I can't think of anything else. Maybe someone else has a better idea.

0

Hi Vele,

You can try this one--
select id, title from data where title LIKE '%PHP developer%' union select * from data

The above query will return the exact string with all other rows in the database.
select id, title from data where title LIKE '%PHP developer%' union select * from data group by title

The above query will return the exact string with all other rows in sorted order in the database.

0

Although, i have used naw33n's solution, manojjena1982's solution seems usefull to. mwasif's solution needs some time to be absorbed.

Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.