how to select record whose matching percentage is higher than other using like operator in sql server?

后端 未结 3 901
温柔的废话
温柔的废话 2021-01-14 23:45

I have set of records which I need to search using criteria. But criteria is returning me multiple rows.

So I need top 2 records which are having maximum percentage

3条回答
  •  隐瞒了意图╮
    2021-01-15 00:30

    You could use Full text search. Using ContainsTable you can get a RANK for each record describing how weel it fit the search pattern. Then you can order your results by that rank and then use select top N to get only the best N results.

    Implementing full text search is easy and fast, specially if you need simple queries like yours.

    Resources:

    • Implementing full text search and basic usage.
    • Part 3 of a series, focused on ranked queries with containstable and freetexttable.
    • ContainsTable reference. Also you can find a lot of info about this here on stackoverflow.

    Hope it helps.

提交回复
热议问题