Categories
How can I select from the database all records that match at least 4 columns or more in value with my data?
There is data and there is a database. We need to find all records with matches, which are >= 4 in columns
Answer the question
In order to leave comments, you need to log in
Well, for example:
SELECT * FROM ( SELECT *, CASE WHEN col_a = a THEN 1 ELSE 0 END + CASE WHEN col_b = b THEN 1 ELSE 0 END + CASE WHEN col_c = c THEN 1 ELSE 0 END + ... AS colcount FROM table WHERE col_a = a OR col_b = b OR ... ) q WHERE colcount >= 4
Didn't find what you were looking for?
Ask a Question
731 491 924 answers to any question