Skip to content
Advertisement

how to return a unique set of characters within a field (SQL)?

Basically i am trying to return any fields within the tag column that contain up_ up1_ up2_ up3, up4_.

the problem i’m facing is i only want to show these tags and not the others.

The field contains a mixture of characters on each row so i’m finding it difficult to use a CASE statement substr.

I’ve been able to return the entire field using this sql:

any ideas?

Many thanks, Jonathon

EDIT data within the column:

I want to be able to return only the UP1_ and Up_ tags. and want to remove the rest..

EDIT 2

This column is populated by an external site

Advertisement

Answer

For PostgreSQL for instance, you could go with the following:

Please adjust the regular expression in the first line to your exact needs.

For other DB-Systems, swap the substring function for one of the following:

For TSQL, have a look at the “patindex”-function. For Athena, consider the REGEXP_SUBSTR function, as described here: https://docs.aws.amazon.com/redshift/latest/dg/REGEXP_SUBSTR.html

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement