In: Computer Science
write a sql statement that retrieves product ID (ProductID) and name (Name) from Production.product table for all product whose name includes both the words "silver" and "frame"
I have coded the query in MySQL.
Don't forget to upvote if you like my answer
Please comment if you have any queries or suggestions.
Query:
SELECT ProductID, Name from Production.product
WHERE Name LIKE 'silver' AND Name LIKE 'frame'
Explanation:
Using the 'SELECT" statement, we select some particular columns from a table. We use SELECT statement here to select the ProductID and Name column from the Production.product table.
We use the WHERE statement to impose a condition to select those particular rows that satisfy the condition.
The LIKE statement is used to check if a particular column contains a particular substring. For example, 'abc' is a substring of 'abcde'. Here LIKE will return True. We use LIKE to find if for a particular row, the column NAME has both the substrings "silver" and "frame". This is added under the WHERE statement.
So the whole statement retrieves the rows where the Name column has both the words, 'silver' and 'frame' and displays their ProductID and Name columns.
Output:
I had a database like this:
ProductID | Name |
1 | Silver ring |
2 | Silver coloured frame |
3 | Black frame |
4 | Spoons |
THe output is:
ProductID | Name |
2 | Silver coloured frame |