How can I use the query of SQL “contains” for searching the value by specific keywords or phrases?

377    Asked by Unnatigautam in SQL Server , Asked on Jan 10, 2024

 I have been assigned as a data analyst for an e-commerce company. The database of the company includes a table named “products” which has information about the wide range of products for sale. How can I use the SQL containing a query for searching the products that have a specific keyword or phrase, such as “waterproof”?

Answered by Chloe Burgess

 In SQL you can use the “SQL CONTAINS query” for searching the products in your dataset by just using the specific keywords or even phrases. Here is the example given of how you can do so:-

Let us consider a scenario where you have a table whose name is “products” with the column name “description”. In this particular scenario, your objective is to find the product which contains the word or phrase “waterproof”. You can do so by using SQL contains query:-

SELECT *
FROM products
WHERE CONTAINS(description, ‘waterproof’);

This above SQL query would print you for the product or products which have the phrase included “waterproof”. In other words, this query will retrieve all the rows where the description would contain the specified word or phrase.



Your Answer

Interviews

Parent Categories