Interview questions on sql for freshers/beginners

What is sql?

SQL stands for structured query language.Its a special purpose programing language use to manage the data in RDBMS systems.

Which sql statement is use to extract data from database?

Select command is used to extract the data from a database.

Which sql statement is use to insert data into databse?

Insert statement.

Which statement is use to update data into database?

Update statement.

which statement is use to delete all rows from table?


which statement is used to delete a row from the table?

Drop statement.

Which statement is used to delete the data from rows?

Delete statement.

What is DDL?

Data Definition Language.It is used to define the structure that holds the data.


What is DML?

Data Manipulation Language.It is used to manipulate the data.

E.g.->Data insertion,Deletion,updation inside table.

what is DCL?

Data control language.It controls the visibility of data.

E.g.->Grant permission and set privilages to create table.

Advanteges of sql?

1.Sql is easy to learn.

2.If one knows sql then he/she can access any databases like oracle,mysql,db2 etc.

3.We can perform complex as well as sophisticated task with the help of sql.

What are stored procedures?

Stored procedures are collection of sql queries procedure and can take inputs and send outputs.It helps to execute queries much faster.Procedures are precompiled and stored in database.

What is trigger?

A trigger is a set of command that get executed when an event occurs ona table.

For eg-> insert into table name values(‘$a,$b); Here trigger is insert which is a command, used to insert data inside the table.

What are cluster ?

Clusters are physically stored data.It makes data retreival faster.
what are non-clusters?

Non-clusters are logically stored data,it makes insert and update command to work faster.

for sql queries we are using an example of college management system,where all information of students, staffs etc is available.

Name of Table is “student” and rows are name,id,roll_number,class,section,phone_number

Write a sql query to insert data inside table “college”?

insert into student values($name,$id,$roll_number,$class,$section);

Write a sql query to get all details from a table?

select * from student;

sql query to get data from rows name,roll_number?

select name,roll_number from student;

how can we retreive the data of students whose name starts with letter A?

select name from student where name like ‘A%’;

How can we retreive data from table(student) by last letter of the name?

Select name from student where name like’%A’;

Where we use ‘where’ clause?

We use where clause when we want to retrieve data from a particular row.

Where we use order by clause?

We use order by statement to arrange data in ascending or descending order.

SQl query to find the current date and time?

Select sysdate from dual;

Write a query using order by clause?

Select name from student where section=”A” order by name asc;

Why do we use having clause?

We use having a clause for aggregate functions.

E.g. of aggregate functions are max(),count(),min(),avg() etc.

Where we use group by clause?

We use group by clause with a Select statement to arrange identical data groups.

Write a SQL for data update?

Update table(student) set section=’B’where Name=’John’;

SQL query to find the five toppers of the class?

Select name, percentage from employees where rownum=5 order by percentage desc;

How can I find a student from a table whose name length is 7?

Select name from student where length(name)=7;

Other sql queries generally asked in interviews:-

Sql query to find max salary from table employee?
Select max(salary) from employees;

Sql query to find list of employees not from city london?

Select ename from employees here city<>’london’;