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 |
Recommended Posts:
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- SQL | SELECT Query
- SQL query to find unique column values from table
- PHP | MySQL Select Query
- SQL query using COUNT and HAVING clause
- SQL Query to find the Nth Largest Value in a Column using Limit and Offset
- Query to find 2nd largest value in a column in Table
- SQL query to find second highest salary?
- Structured Query Language (SQL)
- SQL | Query Processing
- What are the Best Ways to Write a SQL Query?
- Features of Structured Query Language (SQL)
- SQL Query Complexity
- SQL | SELECT TOP Clause
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- SELECT INTO statement in SQL
- Select statement in MS SQL Server
- Select top in MS SQL Server
- Insert Into Select statement in MS SQL Server
- SQL | SELECT data from Multiple Tables
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

