MYSQL - select that returns everything you have before a '-' or '/'

Asked

Viewed 44 times

0

I have a column in my table 'RG_ORGAO' and there we will find filled rows like this:

SSP - PUBLIC SECURITY SECRETARIAT

DGPC - GENERAL DIRECTORATE OF CIVIL POLICE

DMV - TRANSIT DEPARTMENT

I need to make a select that returns to me everything that contains before the '-'

  • You can have a look, https://answall.com/questions/97102/query-para-pega-palavra-apos-determinate-caractere I hope it helps

1 answer

2


Return to substring before first occurrence of delimiter "-":

SELECT SUBSTRING_INDEX('foo-bar-bar', '-', 1) as result;

Outputs result = "foo"

  • Thanks worked out here.. , one more question I can use more than once in the same column?

  • What do you mean more than once in the column? it doesn’t change the die, so you can use it endlessly.

  • SUBSTRING_INDEX SEPEARA ON A VECTOR AND YOU DETERMINE THE SEPARATION FIELD, IN THE CASE OF "-" SELECT SUBSTRING_INDEX(RG_ORGAO, "-", 1);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.