
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Find rows with a match in a pipe delimited column with MySQL
To find a match, use regular expressions in MySQL. Let us first create a table −
mysql> create table DemoTable -> ( -> Value varchar(60) -> ); Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('8|56|78|45'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable values('9876'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('98|8'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('3|8|9'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('97|94'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('103|104|110|8|97'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable ;
This will produce the following output −
+------------------+ | Value | +------------------+ | 8|56|78|45 | | 9876 | | 98|8 | | 3|8|9 | | 97|94 | | 103|104|110|8|97 | +------------------+ 6 rows in set (0.00 sec)
Here is the query to find rows with a match in a pipe-delimited column −
mysql> select *from DemoTable -> where Value regexp '\|8\|';
This will produce the following output −
+------------------+ | Value | +------------------+ | 3|8|9 | | 103|104|110|8|97 | +------------------+ 2 rows in set (0.00 sec)
- Related Articles
- MySQL select distinct rows into a comma delimited list column?
- Select rows containing a string in a specific column with MATCH and AGAINST in MySQL
- How to collapse rows into a comma-delimited list with a single MySQL Query?
- Find rows where column value ends with a specific substring in MySQL?
- Match the Column A with Column B.
- Combining multiple rows into a comma delimited list in MySQL?
- MySQL query to count rows with a specific column?
- Replacing numbers on a comma delimited result with MySQL?
- How to find repeated rows and display there count in a separate column with MySQL?
- Match the items in column A with those in column B:
- Match items in Column A with the terms of Column B.
- Find records with a specific last digit in column with MySQL
- Match column I with column II:
- Match the items given in Column A with that in Column B
- Match the organisms in Column A with their action in Column B.

Advertisements