'How to extract second word in a string in SQL separated by underscore?

I am trying to extract only the second word in a string. For example

Name[Column Name]
Patrick_Andrew_Marsh
Rajesh_Kumar_Sinha

I want to extract Andrew and Kumar from the column and similarly for all the other names. How do I do it?



Solution 1:[1]

You can use the split function for this purpose

 select split(name, '_')[1]  from table

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1