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
MySQL query to get a field value that does not contain empty spaces?
Use NOT LIKE for this. Let us first create a table −
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentFullName varchar(40) ); Query OK, 0 rows affected (0.66 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable(StudentFullName) values('JohnSmith');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable(StudentFullName) values('John Doe');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable(StudentFullName) values('Adam Smith');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable(StudentFullName) values('CarolTaylor');
Query OK, 1 row affected (0.19 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+----+-----------------+ | Id | StudentFullName | +----+-----------------+ | 1 | JohnSmith | | 2 | John Doe | | 3 | Adam Smith | | 4 | CarolTaylor | +----+-----------------+ 4 rows in set (0.00 sec)
Following is the query to get a field value that does not contain empty spaces −
mysql> select *from DemoTable where StudentFullName NOT LIKE '% %';
This will produce the following output −
+----+-----------------+ | Id | StudentFullName | +----+-----------------+ | 1 | JohnSmith | | 4 | CarolTaylor | +----+-----------------+ 2 rows in set (0.18 sec)
Advertisements
