Example of SQL SELECT WHERE Field Contains Words
To search for a record that contains a specific word in a specific field, we will use SELECT statement in SQL with WHERE clause to filter the results based on a specific word.
Consider a table named products with columns product_id and product_name. We want to select products where the product name contains the word “chair“.
Query:
CREATE TABLE products (
product_id INT,
product_name VARCHAR(100)
);
INSERT INTO products (product_id, product_name) VALUES
(1, 'Office Chair'),
(2, 'Dining Chair'),
(3, 'Desk Lamp'),
(4, 'Armchair');
SELECT * FROM PRODUCTS;
Output:
We search for the word ‘chair using 2 approaches, discussed below:
- Using LIKE Operator with wildcards
- Using Full taxt search (MATCH .. .AGAINST)
SQL SELECT WHERE Field Contains Words
The SQL SELECT WHERE field Contains Words” in SQL is used to find data with specific words in it. It helps us to find patterns in text fields. One more way to do this is by using full-text search, which searches entire blocks of text to find what we need.
In simple words, we can say SQL gives us ways to find data based on words or phrases in fields which makes it easier to get the required information.