
- 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
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 Articles
- A single MySQL query to update only specific records in a range without updating the entire column
- MySQL query to check if a string contains a word?
- MySQL query to display records ordered by numeric difference?
- MySQL update multiple records in a single query?
- Get the first 10 rows followed by the syntax to display remaining row records with a single MySQL query
- MySQL regexp to display only records with strings or strings mixed with numbers. Ignore only the number records
- MySQL query to display only 15 words from the left?
- 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
- MySQL query to order records but fix a specific name and display rest of the values (only some) random
- Display matching repeated date records only once in MySQL
- MySQL query to display only the empty and NULL values together?
- Implement MySQL IN for 2 columns to display only selected records
- MongoDB query to update only a single item from voting (up and down) records?
- MySQL query to display records ordered by DESC while skipping some?

Advertisements