Created
February 16, 2023 04:36
-
-
Save danieldram/44ab8bddbb48ad21725c49e4bab727ce to your computer and use it in GitHub Desktop.
Fuzzy Search with SQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Serach for SANDRA across multiple tables and columns | |
SELECT * FROM ( | |
SELECT *, | |
( | |
CASE | |
WHEN first_name LIKE '%SANDRA%' THEN 1 | |
ELSE 0 | |
END | |
) AS match_strength | |
FROM actor | |
UNION ALL | |
SELECT *, | |
( | |
CASE | |
WHEN first_name like '%SANDRA%' THEN 1 | |
ELSE 0 | |
END | |
)as match_strength | |
FROM actor_tv | |
) | |
AS x | |
WHERE match_strength > 0 | |
ORDER BY match_strength DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment