AdventureWorks Database: Name with the words Mountain and Black

SQL Query - AdventureWorks: Exercise-55 with Solution

55. From the following table write a query in SQL to search for name which contains both the word 'Mountain' and the word 'Black'. Return Name and color.

Sample table: Production.Product

Click to view Full table

Sample Solution:

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

Sample Output:

name                         |color|
HL Mountain Frame - Black, 42|Black|
HL Mountain Frame - Black, 44|Black|
HL Mountain Frame - Black, 48|Black|
HL Mountain Frame - Black, 46|Black|
HL Mountain Frame - Black, 38|Black|
Mountain-100 Black, 38       |Black|
Mountain-100 Black, 42       |Black|
Mountain-100 Black, 44       |Black|
Mountain-100 Black, 48       |Black|

Contribute your code and comments through Disqus.

Previous: Products with Mountain or Road in the name.
Next: Product names that begin with the prefix chain.

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