How do I get a part of a string with SQL? (part 1)

Remember these text functions in Excel?

left (string, no of chars) retrieves specified number of characters from the left of the string
mid (string, beginning, end) retrieves specified number of characters from the middle of the string
right (string, no of chars) retrieves specified number of characters from the right of the string

You can also use them in SQL!

 

NB! it’s only MySQL that supports them in a syntax that’s identical to the one in Excel.

If you happen to be using SQL Server or PostgreSQL, you might have to do a little workaround (see code above) before obtaining the same end result

Happy SQL-ing!