Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
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)
Advertisements
