D
D
dNertyco2021-12-18 00:32:44
SQL
dNertyco, 2021-12-18 00:32:44

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

1 answer(s)
G
galaxy, 2021-12-18
@dNertyco

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 your question

Ask a Question

731 491 924 answers to any question