
- 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
How to check if a specific country code exists in a cell with MySQL?
For specific value, use FIND_IN_SET(). Let us first create a −
mysql> create table DemoTable1439 -> ( -> CountryId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CountryCode varchar(20) -> ); Query OK, 0 rows affected (0.49 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1439(CountryCode) values('1022_US,7894_UK'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1439(CountryCode) values('6567_AUS,7894_UK'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1439(CountryCode) values('6567_AUS'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select −
mysql> select * from DemoTable1439;
This will produce the following output −
+-----------+------------------+ | CountryId | CountryCode | +-----------+------------------+ | 1 | 1022_US,7894_UK | | 2 | 6567_AUS,7894_UK | | 3 | 6567_AUS | +-----------+------------------+ 3 rows in set (0.00 sec)
Following is the query to check if country code exists in a cell −
mysql> select * from DemoTable1439 -> where find_in_set('6567_AUS',CountryCode) > 0;
This will produce the following output −
+-----------+------------------+ | CountryId | CountryCode | +-----------+------------------+ | 2 | 6567_AUS,7894_UK | | 3 | 6567_AUS | +-----------+------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to check if a MySQL database exists?
- How To Check If Cell Begins Or Ends With A Specific Character In Excel?
- How to check if a table already exists in the database with MySQL with INFORMATION_SCHEMA.TABLES.?
- How to check if value exists with MySQL SELECT 1?
- How to set country code to column values with phone numbers in MySQL?
- How To Check If The First Letter In A Specific Cell Is Capital In Excel?
- Check if a value exists in a column in a MySQL table?
- How to check if a variable exists in JavaScript?
- How to check if a column exists in Pandas?
- How to check if a file exists in Golang?
- How to check if a file exists in Perl?
- Check if a user exists in MySQL and drop it?
- How to check if a key exists in a Python dictionary?
- How to check if a File Type Exists in a Directory?
- Check if value exists in a comma separated list in MySQL?

Advertisements