When I fetch a field using Sql query, I get a string - [test1, test2, test3, test4]. I want the first word of the string i.e. test1. How should i write my query for the same using sql?
Asked
Active
Viewed 251 times
-2
-
Which DBMS product are you using? "SQL" is just a query language used by all relational databases, not the name of a specific database product. Please add a [tag](https://stackoverflow.com/help/tagging) for the database product you are using. [Why should I tag my DBMS](https://meta.stackoverflow.com/questions/388759/) – Dec 16 '21 at 15:51
-
Does this answer your question? [Is storing a delimited list in a database column really that bad?](https://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad) – Progman Dec 16 '21 at 19:26
1 Answers
1
In mysql, to skip the [
, use substr(yourcolumn from 2)
. To get up to the first comma then, use substring_index:
substring_index(substr(yourcolumn from 2), ',', 1)

ysth
- 96,171
- 6
- 121
- 214