FIND_IN_SET Returns the position of a string within a list of strings
FIND_IN_SET(string, string_list)
SELECT FIND_IN_SET("ram", "naresh,suresh,ram");
("ram,66,telugu")
"cat,dog,ele,hen"
Database changed
MariaDB [vlrinst]> select find_in_set("hen","dog,hen,ele,cat");
+--------------------------------------+
| find_in_set("hen","dog,hen,ele,cat") |
+--------------------------------------+
| 2 |
+--------------------------------------+
1 row in set (0.001 sec)
MariaDB [vlrinst]> select find_in_set("kphb",loc) from emp;
+-------------------------+
| find_in_set("kphb",loc) |
+-------------------------+
| 1 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
| 0 |
+-------------------------+
9 rows in set (0.001 sec)
MariaDB [vlrinst]> select * from emp;
+----+---------+-----------+------+-------+
| id | name | loc | age | sal |
+----+---------+-----------+------+-------+
| 10 | venkat | kphb | 35 | 30000 |
| 11 | praveen | pune | 28 | 35000 |
| 12 | mounika | hyderabad | 22 | 39000 |
| 13 | revathi | jntu | 26 | 20000 |
| 14 | anji | gutta | 28 | 20000 |
| 15 | harika | lb nagar | 26 | 30100 |
| 16 | praveen | jntu | 33 | 100 |
| 17 | pandu | munipeda | 35 | 30300 |
| 18 | pandu | pune | 23 | 39300 |
+----+---------+-----------+------+-------+
9 rows in set (0.000 sec)
MariaDB [vlrinst]> select find_in_set("jntu",loc) from emp;
+-------------------------+
| find_in_set("jntu",loc) |
+-------------------------+
| 0 |
| 0 |
| 0 |
| 1 |
| 0 |
| 0 |
| 1 |
| 0 |
| 0 |
+-------------------------+
9 rows in set (0.000 sec)
MariaDB [vlrinst]> select find_in_set("jntu",loc),id from emp;
+-------------------------+----+
| find_in_set("jntu",loc) | id |
+-------------------------+----+
| 0 | 10 |
| 0 | 11 |
| 0 | 12 |
| 1 | 13 |
| 0 | 14 |
| 0 | 15 |
| 1 | 16 |
| 0 | 17 |
| 0 | 18 |
+-------------------------+----+
9 rows in set (0.001 sec)
MariaDB [vlrinst]>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.