Skip to content
Related Articles

Related Articles

SQL | Query to select NAME from table using different options
  • Last Updated : 19 Aug, 2020

Let us consider the following table named “Geeks” :

G_IDFIRSTNAMELASTNAMEDEPARTMENT
1MohanAroraDBA
2NishaVermaAdmin
3VishalGuptaDBA
4AmitaSinghWriter
5VishalDiwanAdmin
6VinodDiwanReview
7SheetalKumarReview
8GeetaChauhanAdmin
9MonaMishraWriter

SQL query to write “FIRSTNAME” from Geeks table using the alias name as NAME.

Select FIRSTNAME AS NAME 
from Geeks;

Output –



NAME
Mohan
Nisha
Vishal
Amita
Vishal
Vinod
Sheetal
Geeta
Mona

SQL query to write “FIRSTNAME” from Geeks table in upper case.

Select upper(FIRSTNAME) 
from Geeks;

Output –

(No column name)
MOHAN
NISHA
VISHAL
AMITA
VISHAL
VINOD
SHEETAL
GEETA
MONA

SQL query to find the first three characters of FIRSTNAME from Geeks table.

Select substring(FIRSTNAME, 1, 3) 
from Geeks;

Output –



(No column name)
Moh
Nis
Vis
Ami
Vis
Vin
She
Gee
Mon

SQL query to write the FIRSTNAME and LASTNAME from Geeks table into a single column COMPLETENAME with a space char should separate them.

Select CONCAT(FIRSTNAME, ' ', LASTNAME) AS 'COMPLETENAME' 
from Geeks;

Output –

COMPLETENAME
Mohan Arora
Nisha Verma
Vishal Gupta
Amita Singh
Vishal Diwan
Vinod Diwan
Sheetal Kumar
Geeta Chauhan
Mona Mishra

Write an SQL query to print all Worker details from the Geeks table order by FIRSTNAME Ascending.

Select * 
from Geeks 
order by FIRSTNAME asc;

Output –

G_IDFIRSTNAMELASTNAMEDEPARTMENT
4AmitaSinghWriter
8GeetaChauanAdmin
1MohanAroraDBA
9MonaMishraWriter
2NishaVermaAdmin
7SheetalKumarReview
6VinodDiwanReview
3VishalGuptaDBA
5VishalDiwanAdmin

My Personal Notes arrow_drop_up
Recommended Articles
Page :