

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to display only the records that contains single word?
For this, you can filter records on the basis of LIKE. Let us first create a table −
mysql> create table DemoTable ( Name varchar(50) ); Query OK, 0 rows affected (0.50 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Adam Smith'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('Carol'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values('David Miller'); 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 −
+--------------+ | Name | +--------------+ | John Smith | | John | | Adam Smith | | Carol | | David Miller | +--------------+ 5 rows in set (0.00 sec)
Following is the query to display records containing a single word. NOT LIKE is used here to exclude records with more than one word i.e. NOT LIKE '% %' −
mysql> select *from DemoTable where Name not like '% %';
This will produce the following output −
+-------+ | Name | +-------+ | John | | Carol | +-------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL query to check if a string contains a word?
- A single MySQL query to update only specific records in a range without updating the entire column
- MySQL query to display only 15 words from the left?
- MySQL update multiple records in a single query?
- MySQL regexp to display only records with strings or strings mixed with numbers. Ignore only the number records
- MySQL query to display records ordered by numeric difference?
- Display matching repeated date records only once in MySQL
- MySQL query to display only the empty and NULL values together?
- Get the first 10 rows followed by the syntax to display remaining row records with a single MySQL query
- MySQL query to display the count of distinct records from a column with duplicate records
- MySQL query to subtract date records with week day and display the weekday with records
- Implement MySQL IN for 2 columns to display only selected records
- MongoDB query to skip first 5 records and display only the last 5 of them
- MySQL query to order records but fix a specific name and display rest of the values (only some) random
- MySQL query to count records that begin with specific letters
Advertisements