SQL | Query to select NAME from table using different options
Let us consider the following table named “Geeks” :
G_ID | FIRSTNAME | LASTNAME | DEPARTMENT |
---|---|---|---|
1 | Mohan | Arora | DBA |
2 | Nisha | Verma | Admin |
3 | Vishal | Gupta | DBA |
4 | Amita | Singh | Writer |
5 | Vishal | Diwan | Admin |
6 | Vinod | Diwan | Review |
7 | Sheetal | Kumar | Review |
8 | Geeta | Chauhan | Admin |
9 | Mona | Mishra | Writer |
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_ID | FIRSTNAME | LASTNAME | DEPARTMENT |
---|---|---|---|
4 | Amita | Singh | Writer |
8 | Geeta | Chauan | Admin |
1 | Mohan | Arora | DBA |
9 | Mona | Mishra | Writer |
2 | Nisha | Verma | Admin |
7 | Sheetal | Kumar | Review |
6 | Vinod | Diwan | Review |
3 | Vishal | Gupta | DBA |
5 | Vishal | Diwan | Admin |
Please Login to comment...