AdventureWorks Database: Products with Mountain or Road in the name

SQL Query - AdventureWorks: Exercise-54 with Solution

54. From the following table write a query in SQL to retrieve all the products that contain either the phrase Mountain or Road. Return name, and color columns.

Sample table: Production.Product

Click to view Full table

Sample Solution:

SELECT Name,color  
FROM Production.Product  
WHERE to_tsvector(name) @@ to_tsquery('Mountain | Road');

Sample Output:

name                            |color       |
Mountain End Caps               |            |
Road End Caps                   |            |
LL Mountain Rim                 |            |
ML Mountain Rim                 |            |
HL Mountain Rim                 |            |
LL Road Rim                     |            |
ML Road Rim                     |            |
HL Road Rim                     |            |
LL Mountain Seat Assembly       |            |

SQL AdventureWorks Editor:

Practice Online

Contribute your code and comments through Disqus.

Previous: Find products containing Mountain for $80.99.
Next: Name with the words Mountain and Black.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Share this Tutorial / Exercise on : Facebook and Twitter

SQL: Tips of the Day

T-SQL Cast versus Convert?

CONVERT is SQL Server specific, CAST is ANSI.

CONVERT is more flexible in that you can format dates etc. Other than that, they are pretty much the same. If you don't care about the extended features, use CAST.

Ref : https://bit.ly/3VKT5M8