w3resource

AdventureWorks Database: Searches for the word red in the name column

SQL Query - AdventureWorks: Exercise-52 with Solution

52. From the following table write a query in SQL that searches for the word 'red' in the name column. Return name, and color columns from the table.

Sample table: Production.Product


Click to view Full table

Sample Solution:

SELECT Name, Color   
FROM Production.Product 
WHERE to_tsvector(name) @@ to_tsquery('red');

Sample Output:

name                   |color|
-----------------------+-----+
Paint - Red            |     |
HL Road Frame - Red, 58|Red  |
Sport-100 Helmet, Red  |Red  |
HL Road Frame - Red, 62|Red  |
HL Road Frame - Red, 44|Red  |
HL Road Frame - Red, 48|Red  |
HL Road Frame - Red, 52|Red  |
HL Road Frame - Red, 56|Red  |
LL Road Frame - Red, 44|Red  |
LL Road Frame - Red, 48|Red  |
LL Road Frame - Red, 52|Red  |
LL Road Frame - Red, 58|Red  |
LL Road Frame - Red, 60|Red  |
...

SQL AdventureWorks Editor:

Practice Online


Contribute your code and comments through Disqus.

Previous: Orders with orderqtys, unitpricediscount, totaldues.
Next: Find products containing Mountain for $80.99.

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