- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 select everything to left of last space in a column with name records
For this, you can use LEFT(). Let us first create a table −
mysql> create table DemoTable1939 ( FullName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1939 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1939 values('Robert Downey, Jr.'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1939 values('Sylvester Stallone'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1939 values('Chris Hemsworth'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1939;
This will produce the following output −
+--------------------+ | FullName | +--------------------+ | Adam Smith | | Robert Downey, Jr. | | Sylvester Stallone | | Chris Hemsworth | +--------------------+ 4 rows in set (0.00 sec)
Here is the query to select everything to left of last space
mysql> select LEFT(FullName, LENGTH(FullName) - LOCATE(' ', REVERSE(FullName))+1) from DemoTable1939;
This will produce the following output −
+---------------------------------------------------------------------+ | LEFT(FullName, LENGTH(FullName) - LOCATE(' ', REVERSE(FullName))+1) | +---------------------------------------------------------------------+ | Adam | | Robert Downey, | | Sylvester | | Chris | +---------------------------------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL query to remove everything except the last 7 characters in column record
- Add a column count in a MySQL query on the basis of last name records?
- MySQL query to select records with a particular date?
- Select the table name as a column in a UNION select query with MySQL?
- MySQL query to select all the records only from a specific column of a table with multiple columns
- MySQL query to select records with a particular date and time?
- MySQL query to display columns name first name, last name as full name in a single column?
- MySQL query to select top 10 records?
- MySQL query to select bottom n records
- MySQL query to display the count of distinct records from a column with duplicate records
- How to select a column name with spaces in MySQL?
- Find records with a specific last digit in column with MySQL
- MySQL query to remove Null Records in a column?
- MySQL query to conduct a basic search for a specific last name in a column
- MySQL SELECT query to return records with specific month and year

Advertisements