
- 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
Display records where first and last name begins with the same letter in MySQL
To check for the 1st letter of the first and last name, you need to use the LEFT().
Let us first create a table −
mysql> create table DemoTable789 ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.78 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable789 values('Adam','Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable789 values('Tom','Taylor'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable789 values('Bob','Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable789 values('David','Miller'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable789;
This will produce the following output -
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Adam | Smith | | Tom | Taylor | | Bob | Brown | | David | Miller | +-----------+----------+ 4 rows in set (0.00 sec)
Display records where first and last name begins with the same letter in MySQL −
mysql> select *from DemoTable789 where upper(left(FirstName,1))=upper(left(LastName,1));
This will produce the following output -
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Tom | Taylor | | Bob | Brown | +-----------+----------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL GROUP BY and CONCAT() to display distinct first and last name
- Need to populate autocomplete with records on the basis of first and last name of schools in MySQL?
- Validate the first name and last name with Java Regular Expressions
- MySQL query to display columns name first name, last name as full name in a single column?
- How to display first day and last day of the month from date records in MySQL?
- Split First name and Last name using JavaScript?
- Select Statement to retrieve the same first names with similar last name (but different case) using MySQL?
- Group concatenate the last name from a MySQL column and set a condition to display limited records
- Searching 2 fields at the same time to fetch a specific First Name and Last Name from a table in MySQL
- Order MySQL records randomly and display name in Ascending order
- Count numbers with same first and last digits in C++
- Count substrings with same first and last characters in C++
- Program to find a sublist where first and last values are same in Python
- How to display the count from distinct records in the same row with MySQL?
- MongoDB query to skip first 5 records and display only the last 5 of them
Advertisements