Question: MySql A column that returns the third word in the product_name in the products table. If there is no third word, it should return an

MySql

A column that returns the third word in the product_name in the products table. If there is no third word, it should return an empty string. You can do this using IF and SUBSTRING_INDEX. Hint, this is complicated, the idea is that you write expression2 using SUBSTRING_INDEX that will return the 1st word if there is only one word, or the 2nd word if there are 2 words. Write expression3 using SUBSTRING_INDEX that will return the 1st word if there is only one word, or the 2nd word if there are 2 words and the 3rd word if there are three words. Then combine expression2 and expression3 with if as follows: IF ( expression2 != expresion3 , expression3, '') AS third_name Order by product_name.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!