Search sort by parameter match count in the query? PostgreSQL
Posted
by Ben Dauphinee
on Stack Overflow
See other posts from Stack Overflow
or by Ben Dauphinee
Published on 2010-06-18T14:55:37Z
Indexed on
2010/06/18
15:03 UTC
Read the original article
Hit count: 267
I am working on a search query in PostgreSQL, and one of the things I do is sort my query results by the number of parameters matched. I have no clue how this can be done. Does anyone have a suggestion or solution?
Table
brand color type engine
Ford Blue 4-door V8
Maserati Blue 2-door V12
Saturn Green 4-door V8
GM Yellow 1-door V4
Current Query
SELECT brand FROM table WHERE color = 'Blue' or type = '4-door' or engine = 'V8'
Result Should Be
Ford (3 match)
Saturn (2 match)
Maserati (1 match)
© Stack Overflow or respective owner