DEV Community

rahul
rahul

Posted on • Updated on

What are the top 9 SQL Queries for freshers?

In general, query is a request for something. But in the world of programming query means retrieving data from the database with commands that are preset. i.e. SELECT, INSERET, SUM, WHERE etc.
Furthermore, if you wish to explore more about the SQL, DBMS you can visit the page below.
SQL Queries are asked directly in interview as it tests both your practical as well as theoretical knowledge.
Here are the top 9 SQL queries for freshers and for more practice check the references.

Table EmployeeDetails
TABLE EmployeeDetails

Tabl EmployeeSalary
TABLE EmployeeSalary

Que-1 Write an SQL query to find the MAX, MIN and AVERAGE salary of the employees?
Ans- An SQL aggregate function is used to calculate the MAX(), MIN() and AVG() salary of the employees.
SELECT Max(Salary),
MIN(Salary),
AVG(Salary)
FROM Employee Salary;

Que-2 Write an SQL Query to fetch common records between two tables?
Ans- In the SQL server, we can use the INTERSECT() Operator to fetch the data i.e. common in between the two statements.
SELECT * FROM EmployeeSalary
INTERSECT
SELECT * FROM ManagerSalary;

Que-3 Write an SQL Query to display both EmpId and ManagerId together?
Ans- To add two functions together we can use the command CONCAT().
SELECT CONCAT(EmpId,ManagerId) as NewId
FROM EmployeeDetails;

Que-4 Write an SQL Query to display current date and time?
Ans- For SQL Server
SELECT getdate();
For Oracle Server
SELECT SYSDATE FROM DUAL;
For MySQL
SELECT NOW();

Que-5 Write an SQL Query to create new table with data and structure copied from the other table?
Ans- CREATE TABLE NewTable
SELECT * FROM EmployeeSalary;

Que-6 Write an SQL Query to create an empty table with the same structure as some other table?
Ans- CREATE TABLE NewTable
SELECT * FROM EmployeeSalary where 1=0;

Que-7 Write an SQL Query to find all the employees whose salary is between 8000 and 12000?
Ans- SELECT * FROM EmployeeSalary WHERE Salary BETWEEN '5000' AND '12000';

Que-8 Write an SQL Query to fetch the position of a given character(s) in a field?
Ans- The function INSTR() is a case sensitive search. The INSTR() function returns the first occurrence of string in another string.
SELECT INSTR(FullName,'Snow')
FROM EmployeeDetails;

Que-9 Write an SQL query to upper case the name of employee and lower case the city values?
Ans- The SQL Upper and Lower functions can be used to achieve the result.
SELECT UPPER (FullName), LOWER(city)
FROM EmployeeDetails;

This is the end of our top 9 questions that are mostly asked in interviews. Thanks for reading. :)

REFERENCES:-

Top comments (1)

Collapse
 
aman007 profile image
Aman Kumar

very useful