
- 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
Check if a value exists in a column in a MySQL table?
Let us first create a table −
mysql> create table DemoTable807( ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, ClientName varchar(100), ClientCountryName varchar(100) ); Query OK, 0 rows affected (0.64 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable807(ClientName,ClientCountryName) values('Chris','UK'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable807(ClientName,ClientCountryName) values('David','AUS'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable807(ClientName,ClientCountryName) values('Robert','US'); Query OK, 1 row affected (0.74 sec) mysql> insert into DemoTable807(ClientName,ClientCountryName) values('Mike','ENG'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable807;
This will produce the following output −
+----------+------------+-------------------+ | ClientId | ClientName | ClientCountryName | +----------+------------+-------------------+ | 1 | Chris | UK | | 2 | David | AUS | | 3 | Robert | US | | 4 | Mike | ENG | +----------+------------+-------------------+ 4 rows in set (0.00 sec)
Following is the query to check if a value exists in a column in a MySQL table −
mysql> select *from DemoTable807 where ClientCountryName='US';
This will produce the following output −
+----------+------------+-------------------+ | ClientId | ClientName | ClientCountryName | +----------+------------+-------------------+ | 3 | Robert | US | +----------+------------+-------------------+ 1 row in set (0.00 sec)
- Related Articles
- Check that a table exists in MySQL?
- Check if value exists in a comma separated list in MySQL?
- Check if a table is empty or not in MySQL using EXISTS
- How to check if a column exist in a MySQL table?
- How to check if a column exists in Pandas?
- Check if table exists in MySQL and display the warning if it exists?
- Check if a particular value exists in Java LinkedHashMap
- Check if a particular value exists in Java TreeSet
- Check if value exists for a field in a MongoDB document?
- How to check if a table already exists in the database with MySQL with INFORMATION_SCHEMA.TABLES.?
- How To Check Or Find If Value Exists In Another Column?
- Java Program to check if a given value exists in a HashMap
- How to check if a table exists in MySQL and create if it does not already exist?
- Check if a user exists in MySQL and drop it?
- How to check if a MySQL database exists?

Advertisements