Schema and sample data
| product_id | name | price |
|---|---|---|
| 1 | ProBook 450 | 899.00 |
| 2 | Wireless Pro Mouse | 34.99 |
| 3 | Gaming Keyboard | 59.00 |
| 4 | MacBook Pro | 1999.00 |
| 5 | HDMI Adapter | 15.50 |
| 6 | Surface Pro 9 | 1299.00 |
| 7 | USB-C Cable | 12.50 |
Show setup SQL (copy to run)
CREATE TABLE Products (
product_id INT PRIMARY KEY,
name VARCHAR(60) NOT NULL,
price DECIMAL(10,2) NOT NULL
);
INSERT INTO Products (product_id, name, price) VALUES
(1, 'ProBook 450', 899.00),
(2, 'Wireless Pro Mouse', 34.99),
(3, 'Gaming Keyboard', 59.00),
(4, 'MacBook Pro', 1999.00),
(5, 'HDMI Adapter', 15.50),
(6, 'Surface Pro 9', 1299.00),
(7, 'USB-C Cable', 12.50);
From the Products table, return the name and price of every product whose name contains the word Pro. Use a LIKE pattern to match the text anywhere in the name, and sort the result by name in ascending (A to Z) order.
Expected result
| name | price |
|---|---|
| MacBook Pro | 1999.00 |
| ProBook 450 | 899.00 |
| Surface Pro 9 | 1299.00 |
| Wireless Pro Mouse | 34.99 |
Show hint
Use WHERE name LIKE with a pattern. To match text that can appear anywhere in the string, wrap the search word in the multi-character wildcard on both sides. Then add ORDER BY name for the A to Z sort.
Try to write the query yourself before you open this.
Show solution and explanation
SELECT name, price
FROM Products
WHERE name LIKE '%Pro%'
ORDER BY name;
The LIKE operator does pattern matching against a string. Two wildcards are available: % matches any run of zero or more characters, and _ matches exactly one single character. The pattern '%Pro%' therefore reads as "any text, then the letters Pro, then any text", which matches the word wherever it sits in the name. Four rows qualify: MacBook Pro, ProBook 450, Surface Pro 9 and Wireless Pro Mouse.
ORDER BY name then sorts those rows alphabetically; ascending is the default, so no ASC keyword is needed. That gives the M, P, S, W ordering you see in the result.
Be aware that %Pro% matches any substring, not a whole word. A name like Projector or Approval would also match because the letters "pro" appear inside them, and by default SQL Server comparisons are case insensitive, so pro matches too. If you truly need a standalone word, you have to be more explicit (for example searching for ' Pro ' with surrounding spaces, or splitting the string), but for a simple contains search %Pro% is the idiomatic tool.
One performance note: a leading % (as in '%Pro%') makes the predicate non-sargable, meaning SQL Server cannot use a normal index seek on name and must scan every row and test each one. A pattern anchored at the start, such as 'Pro%', has no leading wildcard and can seek into an index on name. On large tables prefer anchored patterns or full-text search when you can; a leading wildcard is convenient but does not scale.