For an application, I need to show search results based upon multiple columns. Searching in multiple columns is not that hard, but I also want to know which column(s) the search query matches the text.
Imagine following 'Blabla' table:
---------------------------------------------------------------------------------------
| column1 | column2 | column 3 |
---------------------------------------------------------------------------------------
| Animals are beautiful | Some text regarding music | Vague statement about politics |
---------------------------------------------------------------------------------------
| Music is not his thing | Green is a color | Random gibberish about music |
---------------------------------------------------------------------------------------
Searching for the word 'music' would be as simple as:
SELECT * FROM Blabla WHERE column1 LIKE '%music%' OR column2 LIKE '%music%' OR column2 LIKE '%music%';
But is there a way in SQL to show that matching columns would be column2
for row 1 and column1
+ column3
for row 2?