- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
Select Statement to retrieve the same first names with similar last name (but different case) using MySQL?
Let us first create a table −
mysql> create table DemoTable623 (FirstName varchar(100),LastName varchar(100),Age int); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable623 values('John','Smith',23); Query OK, 1 row affected (0.66 sec) mysql> insert into DemoTable623 values('Adam','smith',23); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable623 values('Chris','Brown',24); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable623 values('Robert','brown',21); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable623;
This will produce the following output −
+-----------+----------+------+ | FirstName | LastName | Age | +-----------+----------+------+ | John | Smith | 23 | | Adam | smith | 23 | | Chris | Brown | 24 | | Robert | brown | 21 | +-----------+----------+------+ 4 rows in set (0.00 sec)
Here is the query to select statement using MySQL −
mysql> select FirstName from DemoTable623 where lower(LastName) ='smith';
This will produce the following output −
+-----------+ | FirstName | +-----------+ | John | | Adam | +-----------+ 2 rows in set (0.00 sec)
Advertisements