Anda di halaman 1dari 59

Hello friends!

in this post we will see some of the most commonly asked SQL
queries in interviews. The questions will start from very basic questions and
then move to more complex problems. Consider the below two tables for most
of the questions asked here.

Table - EmployeeDetails

EmpId FullName ManagerId DateOfJoining

121 John Snow 321 01/31/2014

321 Walter White 986 01/30/2015

421 Kuldeep Rana 876 27/11/2016

Table - EmployeeSalary

EmpId Project Salary

121 P1 8000

321 P2 1000

421 P1 12000

SQL Query Interview Questions with


Answers
Ques.1. Write a SQL query to fetch the count of employees working in
project 'P1'.
Ans. Here, we would be using aggregate function count() with the SQL where
clause-

SELECT COUNT(*) FROM EmployeeSalary WHERE Project = 'P1';

Ques.2. Write a SQL query to fetch employee names having salary


greater than or equal to 5000 and less than or equal 10000.
Ans. Here, we will use BETWEEN in the 'where' clause to return the empId of
the employees with salary satifying the required criteria and then use it as
subquery to find the fullName of the employee form EmployeeDetails table.

SELECT FullName
FROM EmployeeDetails
WHERE EmpId IN
(SELECT EmpId FROM EmpolyeeSalary
WHERE Salary BETWEEN 5000 AND 10000);

Ques.3. Write a SQL query to fetch project-wise count of employees


sorted by project's count in descending order.
Ans. The query has two requirements - first to fetch the project-wise count
and then to sort the result by that count. For project wise count, we will be
using GROUPBY clause and for sorting, we will use ORDER BY clause on the
alias of the project-count.

SELECT Project, count(EmpId) EmpProjectCount


FROM EmployeeSalary
GROUP BY Project
ORDER BY EmpProjectCount DESC;

Ques.4. Write a query to fetch only the first name(string before space)
from the FullName column of EmployeeDetails table.
Ans. In this question, we are required to first fetch the location of the space
character in the FullName field and then extract the first name out of the
FullName field. For finding the location we will use LOCATE method in mySQL
and CHARINDEX in SQL SERVER and for fetching the string before space, we
will use SUBSTRING OR MID method.
mySQL- Using MID
SELECT MID(FullName, 0, LOCATE(' ',FullName)) FROM EmployeeDetails;

SQL Server-Using SUBSTRING


SELECT SUBSTRING(FullName, 0, CHARINDEX(' ',FullName)) FROM EmployeeDetails;

Also, we can use LEFT which returns the left part of a string till specified number
of characters.
SELECT LEFT(FullName, CHARINDEX(' ',FullName) - 1) FROM EmployeeDetails;

Ques.5. Write a query to fetch employee names and salary records.


Return employee details even if the salary record is not present for
the employee.
Ans. Here, we can use left join with EmployeeDetail table on the left side.

SELECT E.FullName, S.Salary


FROM EmployeeDetails E LEFT JOIN EmployeeSalary S
ON E.EmpId = S.EmpId;

Ques.6. Write a SQL query to fetch all the Employees who are also
managers from EmployeeDetails table.
Ans. Here, we have to use Self-Join as the requirement wants us to analyze
the EmployeeDetails table as two different tables, each for Employee and
manager records.

SELECT DISTINCT E.FullName


FROM EmpDetails E
INNER JOIN EmpDetails M
ON E.EmpID = M.ManagerID;

Ques.7. Write a SQL query to fetch all employee records from


EmployeeDetails table who have a salary record in EmployeeSalary
table.
Ans. Using 'Exists'-
SELECT * FROM EmployeeDetails E
WHERE EXISTS
(SELECT * FROM EmployeeSalary S WHERE E.EmpId = S.EmpId);

Ques.8. Write a SQL query to fetch duplicate records from a table.


Ans. In order to find duplicate records from table we can use GROUP BY on all
the fields and then use HAVING clause to return only those fields whose count
is greater than 1 i.e. the rows having duplicate records.

SELECT EmpId, Project, Salary, COUNT(*)


FROM EmployeeSalary
GROUP BY EmpId, Project, Salary
HAVING COUNT(*) > 1;

Ques.9. Write a SQL query to remove duplicates from a table without


using temporary table.
Ans. Using Group By and Having clause-

DELETE FROM EmployeeSalary


WHERE EmpId IN (
SELECT EmpId
FROM EmployeeSalary
GROUP BY Project, Salary
HAVING COUNT(*) > 1));

Using rowId in Oracle-

DELETE FROM EmployeeSalary


WHERE rowid NOT IN
(SELECT MAX(rowid) FROM EmployeeSalary GROUP BY EmpId);

Ques.10. Write a SQL query to fetch only odd rows from table.
Ans. This can be achieved by using Row_number in SQL server-

SELECT E.EmpId, E.Project, E.Salary


FROM (
SELECT *, Row_Number() OVER(ORDER BY EmpId) AS RowNumber
FROM EmployeeSalary
) E
WHERE E.RowNumber % 2 = 1

Ques.11. Write a SQL query to fetch only even rows from table.
Ans. Using the same Row_Number() and checking that the remainder when
divided by 2 is 0-

SELECT E.EmpId, E.Project, E.Salary


FROM (
SELECT *, Row_Number() OVER(ORDER BY EmpId) AS RowNumber
FROM EmployeeSalary
) E
WHERE E.RowNumber % 2 = 0

Ques.12. Write a SQL query to create a new table with data and
structure copied from another table.
Ans. Using SELECT INTO command-

SELECT * INTO newTable FROM EmployeeDetails;

Ques.13. Write a SQL query to create an empty table with same


structure as some other table.
Ans. Using SELECT INTO command with False 'WHERE' condition-

SELECT * INTO newTable FROM EmployeeDetails WHERE 1 = 0;

This can also done using mySQL 'Like' command with CREATE statement-

CREATE TABLE newTable LIKE EmployeeDetails;


Ques.14. Write a SQL query to fetch common records between two
tables.
Ans. Using INTERSECT-

SELECT * FROM EmployeeSalary


INTERSECT
SELECT * FROM ManagerSalary

Ques.15. Write a SQL query to fetch records that are present in one
table but not in another table.
Ans. Using MINUS-

SELECT * FROM EmployeeSalary


MINUS
SELECT * FROM ManagerSalary

Ques.16. Write a SQL query to find current date-time.


Ans. mySQL-

SELECT NOW();

SQL Server-

SELECT getdate();

Oracle-

SELECT SYSDATE FROM DUAL;

Ques.17. Write a SQL query to fetch all the Employees details from
EmployeeDetails table who joined in Year 2016.
Ans. Using BETWEEN for the date range '01-01-2016' AND '31-12-2016'-

SELECT * FROM EmployeeDetails


WHERE DateOfJoining BETWEEN '01-01-2016' AND date '31-12-2016';
Also, we can extract year part from the joining date (using YEAR in mySQL)-

SELECT * FROM EmployeeDetails


WHERE YEAR(DateOfJoining) = '2016';

Ques.18. Write a SQL query to fetch top n records?


Ans. In mySQL using LIMIT-

SELECT * FROM EmployeeSalary ORDER BY Salary DESC LIMIT N

In SQL server using TOP command-

SELECT TOP N * FROM EmployeeSalary ORDER BY Salary DESC

In Oracle using ROWNUM-

SELECT * FROM (SELECT * FROM EmployeeSalary ORDER BY Salary DESC)


WHERE ROWNUM <= 3;

Ques.19. Write SQL query to find the nth highest salary from table.
Ans. Using Top keyword (SQL Server)-

SELECT TOP 1 Salary


FROM (
SELECT DISTINCT TOP N Salary
FROM Employee
ORDER BY Salary DESC
)
ORDER BY Salary ASC

Using limit clause(mySQL)-

SELECT Salary FROM Employee ORDER BY Salary DESC LIMIT N-1,1;


Ques.20. Write SQL query to find the 3rd highest salary from table
without using TOP/limit keyword.
Ans. The below SQL query make use of correlated subquery wherein in order
to find the 3rd highest salary the inner query will return the count of till we
find that there are two rows that salary greater than other distinct salaries.

SELECT Salary
FROM EmployeeSalary Emp1
WHERE 2 = (
SELECT COUNT( DISTINCT ( Emp2.Salary ) )
FROM EmployeeSalary Emp2
WHERE Emp2.Salary > Emp1.Salary
)

For nth highest salary-

SELECT Salary
FROM EmployeeSalary Emp1
WHERE N-1 = (
SELECT COUNT( DISTINCT ( Emp2.Salary ) )
FROM EmployeeSalary Emp2
WHERE Emp2.Salary > Emp1.Salary
)

50 SQL Query Questions And Answers For Practice


Interview Questions QA Interview SQL Interview Updated: January 29, 2018 Meenakshi
Agarwal sql interview questions
If you want to improve SQL skills, then install a SQL package like MySQL and start
practicing with it. To get you started, we’ve outlined a few SQL query questions in this
post.
Solving practice questions is the fastest way to learn any subject. That’s why we’ve
selected a set of 50 SQL queriesthat you can use to step up your learning. We’ve also
given SQL scripts to create the test data. So, you can use them to create test database
and tables.
Most of the SQL query questions we’ve filtered out of interviews held by top IT MNC like
Flipkart and Amazon. So you’ll gain real-time experience by going through them.

Also, we recommend that you first try to form queries by yourself rather than just
reading them from the post. Try to find answers on your own.

But you can’t start until the required sample data is not in place. You can check out the
tables below that we’ve provided for practice. So first of all, you need to create the test
data in your database software.

By the way, we have a bunch of other posts available for SQL interview preparation. So
if you are interested, then follow the link given below.

💡 Most Frequently Asked SQL Interview Questions.


Let’s Begin Learning SQL.

50 SQL Query Questions


Prepare Sample Data To Practice SQL Skill.
Sample Table – Worker
WORKER_ID FIRST_NAME LAST_NAME SALARY JOINING_DATE DEPARTMENT
001 Monika Arora 100000 2014-02-20 09:00:00 HR

002 Niharika Verma 80000 2014-06-11 09:00:00 Admin

003 Vishal Singhal 300000 2014-02-20 09:00:00 HR

004 Amitabh Singh 500000 2014-02-20 09:00:00 Admin

005 Vivek Bhati 500000 2014-06-11 09:00:00 Admin

006 Vipul Diwan 200000 2014-06-11 09:00:00 Account

007 Satish Kumar 75000 2014-01-20 09:00:00 Account

008 Geetika Chauhan 90000 2014-04-11 09:00:00 Admin

Sample Table – Bonus


WORKER_REF_ID BONUS_DATE BONUS_AMOUNT

1 2016-02-20 00:00:00 5000

2 2016-06-11 00:00:00 3000

3 2016-02-20 00:00:00 4000

1 2016-02-20 00:00:00 4500

2 2016-06-11 00:00:00 3500

Sample Table – Title


WORKER_REF_ID WORKER_TITLE AFFECTED_FROM

1 Manager 2016-02-20 00:00:00

2 Executive 2016-06-11 00:00:00

8 Executive 2016-06-11 00:00:00


5 Manager 2016-06-11 00:00:00

4 Asst. Manager 2016-06-11 00:00:00

7 Executive 2016-06-11 00:00:00

6 Lead 2016-06-11 00:00:00

3 Lead 2016-06-11 00:00:00

To prepare the sample data, you can run the following queries in your database query
executor or on the SQL command line. We’ve tested them with MySQL Server 5.7 and
MySQL Workbench 6.3.8 query browser. You can also download these Softwares and
install them to carry on the SQL exercise.

SQL Script To Seed Sample Data.


CREATE DATABASE ORG;
SHOW DATABASES;
USE ORG;

CREATE TABLE Worker (


WORKER_ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
FIRST_NAME CHAR(25),
LAST_NAME CHAR(25),
SALARY INT(15),
JOINING_DATE DATETIME,
DEPARTMENT CHAR(25)
);

INSERT INTO Worker


(WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING_DATE, DEPARTMENT)
VALUES
(001, 'Monika', 'Arora', 100000, '14-02-20 09.00.00', 'HR'),
(002, 'Niharika', 'Verma', 80000, '14-06-11 09.00.00',
'Admin'),
(003, 'Vishal', 'Singhal', 300000, '14-02-20 09.00.00', 'HR'),
(004, 'Amitabh', 'Singh', 500000, '14-02-20 09.00.00',
'Admin'),
(005, 'Vivek', 'Bhati', 500000, '14-06-11 09.00.00', 'Admin'),
(006, 'Vipul', 'Diwan', 200000, '14-06-11 09.00.00',
'Account'),
(007, 'Satish', 'Kumar', 75000, '14-01-20 09.00.00',
'Account'),
(008, 'Geetika', 'Chauhan', 90000, '14-04-11 09.00.00',
'Admin');

CREATE TABLE Bonus (


WORKER_REF_ID INT,
BONUS_AMOUNT INT(10),
BONUS_DATE DATETIME,
FOREIGN KEY (WORKER_REF_ID)
REFERENCES Worker(WORKER_ID)
ON DELETE CASCADE
);

INSERT INTO Bonus


(WORKER_REF_ID, BONUS_AMOUNT, BONUS_DATE) VALUES
(001, 5000, '16-02-20'),
(002, 3000, '16-06-11'),
(003, 4000, '16-02-20'),
(001, 4500, '16-02-20'),
(002, 3500, '16-06-11');
CREATE TABLE Title (
WORKER_REF_ID INT,
WORKER_TITLE CHAR(25),
AFFECTED_FROM DATETIME,
FOREIGN KEY (WORKER_REF_ID)
REFERENCES Worker(WORKER_ID)
ON DELETE CASCADE
);

INSERT INTO Title


(WORKER_REF_ID, WORKER_TITLE, AFFECTED_FROM) VALUES
(001, 'Manager', '2016-02-20 00:00:00'),
(002, 'Executive', '2016-06-11 00:00:00'),
(008, 'Executive', '2016-06-11 00:00:00'),
(005, 'Manager', '2016-06-11 00:00:00'),
(004, 'Asst. Manager', '2016-06-11 00:00:00'),
(007, 'Executive', '2016-06-11 00:00:00'),
(006, 'Lead', '2016-06-11 00:00:00'),
(003, 'Lead', '2016-06-11 00:00:00');
Once above SQL would run, you’ll see a result similar to the one attached below.

Creating Sample Data to Practice SQL Skill.

50 SQL Query Questions And Answers For Practice.


Q-1. Write An SQL Query To Fetch “FIRST_NAME” From Worker
Table Using The Alias Name As <WORKER_NAME>.
Ans.
The required query is:

Select FIRST_NAME AS WORKER_NAME from Worker;

Q-2. Write An SQL Query To Fetch “FIRST_NAME” From Worker


Table In Upper Case.
Ans.
The required query is:

Select upper(FIRST_NAME) from Worker;

Q-3. Write An SQL Query To Fetch Unique Values Of DEPARTMENT


From Worker Table.
Ans.
The required query is:

Select distinct DEPARTMENT from Worker;


Q-4. Write An SQL Query To Print First Three Characters
Of FIRST_NAME From Worker Table.
Ans.
The required query is:

Select substring(FIRST_NAME,1,3) from Worker;

Q-5. Write An SQL Query To Find The Position Of The Alphabet (‘A’)
In The First Name Column ‘Amitabh’ From Worker Table.
Ans.
The required query is:

Select INSTR(FIRST_NAME, BINARY'a') from Worker where FIRST_NAME = 'Amitabh';


Notes.
 The INSTR method is in case-sensitive by default.
 Using Binary operator will make INSTR work as the case-sensitive function.

Q-6. Write An SQL Query To Print The FIRST_NAME From Worker


Table After Removing White Spaces From The Right Side.
Ans.
The required query is:

Select RTRIM(FIRST_NAME) from Worker;

Q-7. Write An SQL Query To Print The DEPARTMENT From Worker


Table After Removing White Spaces From The Left Side.
Ans.
The required query is:

Select LTRIM(DEPARTMENT) from Worker;


Q-8. Write An SQL Query That Fetches The Unique Values Of
DEPARTMENT From Worker Table And Prints Its Length.
Ans.
The required query is:

Select distinct length(DEPARTMENT) from Worker;

Q-9. Write An SQL Query To Print The FIRST_NAME From Worker


Table After Replacing ‘A’ With ‘A’.
Ans.
The required query is:

Select REPLACE(FIRST_NAME,'a','A') from Worker;

Q-10. Write An SQL Query To Print The FIRST_NAME And


LAST_NAME From Worker Table Into A Single Column
COMPLETE_NAME. A Space Char Should Separate Them.
Ans.
The required query is:

Select CONCAT(FIRST_NAME, ' ', LAST_NAME) AS 'COMPLETE_NAME' from Worker;

Q-11. Write An SQL Query To Print All Worker Details From The
Worker Table Order By FIRST_NAME Ascending.
Ans.
The required query is:

Select * from Worker order by FIRST_NAME asc;


Q-12. Write An SQL Query To Print All Worker Details From The
Worker Table Order By FIRST_NAME Ascending And
DEPARTMENT Descending.
Ans.
The required query is:

Select * from Worker order by FIRST_NAME asc,DEPARTMENT desc;

Q-13. Write An SQL Query To Print Details For Workers With The
First Name As “Vipul” And “Satish” From Worker Table.
Ans.
The required query is:

Select * from Worker where FIRST_NAME in ('Vipul','Satish');

Q-14. Write An SQL Query To Print Details Of Workers Excluding


First Names, “Vipul” And “Satish” From Worker Table.
Ans.
The required query is:

Select * from Worker where FIRST_NAME not in ('Vipul','Satish');

Q-15. Write An SQL Query To Print Details Of Workers With


DEPARTMENT Name As “Admin”.
Ans.
The required query is:

Select * from Worker where DEPARTMENT like 'Admin%';

Q-16. Write An SQL Query To Print Details Of The Workers Whose


FIRST_NAME Contains ‘A’.
Ans.
The required query is:

Select * from Worker where FIRST_NAME like '%a%';

Q-17. Write An SQL Query To Print Details Of The Workers Whose


FIRST_NAME Ends With ‘A’.
Ans.
The required query is:

Select * from Worker where FIRST_NAME like '%a';

Q-18. Write An SQL Query To Print Details Of The Workers Whose


FIRST_NAME Ends With ‘H’ And Contains Six Alphabets.
Ans.
The required query is:

Select * from Worker where FIRST_NAME like '_____h';

Q-19. Write An SQL Query To Print Details Of The Workers Whose


SALARY Lies Between 100000 And 500000.
Ans.
The required query is:

Select * from Worker where SALARY between 100000 and 500000;

Q-20. Write An SQL Query To Print Details Of The Workers Who


Have Joined In Feb’2014.
Ans.
The required query is:

Select * from Worker where year(JOINING_DATE) = 2014 and month(JOINING_DATE)


= 2;
Q-21. Write An SQL Query To Fetch The Count Of Employees
Working In The Department ‘Admin’.
Ans.
The required query is:

SELECT COUNT(*) FROM worker WHERE DEPARTMENT = 'Admin';

Q-22. Write An SQL Query To Fetch Worker Names With Salaries >=
50000 And <= 100000.
Ans.
The required query is:

SELECT CONCAT(FIRST_NAME, ' ', LAST_NAME) As Worker_Name, Salary


FROM worker
WHERE WORKER_ID IN
(SELECT WORKER_ID FROM worker
WHERE Salary BETWEEN 50000 AND 100000);

Q-23. Write An SQL Query To Fetch The No. Of Workers For Each
Department In The Descending Order.
Ans.
The required query is:

SELECT DEPARTMENT, count(WORKER_ID) No_Of_Workers


FROM worker
GROUP BY DEPARTMENT
ORDER BY No_Of_Workers DESC;

Q-24. Write An SQL Query To Print Details Of The Workers Who Are
Also Managers.
Ans.
The required query is:

SELECT DISTINCT W.FIRST_NAME, T.WORKER_TITLE


FROM Worker W
INNER JOIN Title T
ON W.WORKER_ID = T.WORKER_REF_ID
AND T.WORKER_TITLE in ('Manager');

Q-25. Write An SQL Query To Fetch Duplicate Records Having


Matching Data In Some Fields Of A Table.
Ans.
The required query is:

SELECT WORKER_TITLE, AFFECTED_FROM, COUNT(*)


FROM Title
GROUP BY WORKER_TITLE, AFFECTED_FROM
HAVING COUNT(*) > 1;

Q-26. Write An SQL Query To Show Only Odd Rows From A Table.
Ans.
The required query is:

SELECT * FROM Worker WHERE MOD (WORKER_ID, 2) <> 0;

Q-27. Write An SQL Query To Show Only Even Rows From A Table.
Ans.
The required query is:

SELECT * FROM Worker WHERE MOD (WORKER_ID, 2) = 0;

Q-28. Write An SQL Query To Clone A New Table From Another


Table.
Ans.
The general query to clone a table with data is:

SELECT * INTO WorkerClone FROM Worker;


The general way to clone a table without information is:

SELECT * INTO WorkerClone FROM Worker WHERE 1 = 0;


An alternate way to clone a table (for MySQL) without is:

CREATE TABLE WorkerClone LIKE Worker;

Q-29. Write An SQL Query To Fetch Intersecting Records Of Two


Tables.
Ans.
The required query is:

(SELECT * FROM Worker)


INTERSECT
(SELECT * FROM WorkerClone);

Q-30. Write An SQL Query To Show Records From One Table That
Another Table Does Not Have.
Ans.
The required query is:

SELECT * FROM Worker


MINUS
SELECT * FROM Title;

Q-31. Write An SQL Query To Show The Current Date And Time.
Ans.
Following MySQL query returns the current date:

SELECT CURDATE();
Following MySQL query returns the current date and time:

SELECT NOW();
Following SQL Server query returns the current date and time:
SELECT getdate();
Following Oracle query returns the current date and time:

SELECT SYSDATE FROM DUAL;

Q-32. Write An SQL Query To Show The Top N (Say 10) Records Of
A Table.
Ans.
Following MySQL query will return the top n records using the LIMIT method:

SELECT * FROM Worker ORDER BY Salary DESC LIMIT 10;


Following SQL Server query will return the top n records using the TOP command:

SELECT TOP 10 * FROM Worker ORDER BY Salary DESC;


Following Oracle query will return the top n records with the help of ROWNUM:

SELECT * FROM (SELECT * FROM Worker ORDER BY Salary DESC)


WHERE ROWNUM <= 10;

Q-33. Write An SQL Query To Determine The Nth (Say N=5) Highest
Salary From A Table.
Ans.
The following MySQL query returns the nth highest salary:

SELECT Salary FROM Worker ORDER BY Salary DESC LIMIT n-1,1;


The following SQL Server query returns the nth highest salary:

SELECT TOP 1 Salary


FROM (
SELECT DISTINCT TOP n Salary
FROM Worker
ORDER BY Salary DESC
)
ORDER BY Salary ASC;
Q-34. Write An SQL Query To Determine The 5th Highest Salary
Without Using TOP Or Limit Method.
Ans.
The following query is using the correlated subquery to return the 5th highest salary:

SELECT Salary
FROM Worker W1
WHERE 4 = (
SELECT COUNT( DISTINCT ( W2.Salary ) )
FROM Worker W2
WHERE W2.Salary >= W1.Salary
);
Use the following generic method to find nth highest salary without using TOP or limit.

SELECT Salary
FROM Worker W1
WHERE n-1 = (
SELECT COUNT( DISTINCT ( W2.Salary ) )
FROM Worker W2
WHERE W2.Salary >= W1.Salary
);

Q-35. Write An SQL Query To Fetch The List Of Employees With


The Same Salary.
Ans.
The required query is:

Select distinct W.WORKER_ID, W.FIRST_NAME, W.Salary


from Worker W, Worker W1
where W.Salary = W1.Salary
and W.WORKER_ID != W1.WORKER_ID;

Q-36. Write An SQL Query To Show The Second Highest Salary


From A Table.
Ans.
The required query is:
Select max(Salary) from Worker
where Salary not in (Select max(Salary) from Worker);

Q-37. Write An SQL Query To Show One Row Twice In Results


From A Table.
Ans.
The required query is:

select FIRST_NAME, DEPARTMENT from worker W where W.DEPARTMENT='HR'


union all
select FIRST_NAME, DEPARTMENT from Worker W1 where W1.DEPARTMENT='HR';

Q-38. Write An SQL Query To Fetch Intersecting Records Of Two


Tables.
Ans.
The required query is:

(SELECT * FROM Worker)


INTERSECT
(SELECT * FROM WorkerClone);

Q-39. Write An SQL Query To Fetch The First 50% Records From A
Table.
Ans.
The required query is:

SELECT *
FROM WORKER
WHERE WORKER_ID <= (SELECT count(WORKER_ID)/2 from Worker);

Q-40. Write An SQL Query To Fetch The Departments That Have


Less Than Five People In It.
Ans.
The required query is:

SELECT DEPARTMENT, COUNT(WORKER_ID) as 'Number of Workers' FROM Worker GROUP


BY DEPARTMENT HAVING COUNT(WORKER_ID) < 5;

Q-41. Write An SQL Query To Show All Departments Along With


The Number Of People In There.
Ans.
The following query returns the expected result:

SELECT DEPARTMENT, COUNT(DEPARTMENT) as 'Number of Workers' FROM Worker GROUP


BY DEPARTMENT;

Q-42. Write An SQL Query To Show The Last Record From A Table.
Ans.
The following query will return the last record from the Worker table:

Select * from Worker where WORKER_ID = (SELECT max(WORKER_ID) from Worker);

Q-43. Write An SQL Query To Fetch The First Row Of A Table.


Ans.
The required query is:

Select * from Worker where WORKER_ID = (SELECT min(WORKER_ID) from Worker);

Q-44. Write An SQL Query To Fetch The Last Five Records From A
Table.
Ans.
The required query is:

SELECT * FROM Worker WHERE WORKER_ID <=5


UNION
SELECT * FROM (SELECT * FROM Worker W order by W.WORKER_ID DESC) AS W1 WHERE
W1.WORKER_ID <=5;

Q-45. Write An SQL Query To Print The Name Of Employees Having


The Highest Salary In Each Department.
Ans.
The required query is:

SELECT t.DEPARTMENT,t.FIRST_NAME,t.Salary from(SELECT max(Salary) as


TotalSalary,DEPARTMENT from Worker group by DEPARTMENT) as TempNew
Inner Join Worker t on TempNew.DEPARTMENT=t.DEPARTMENT
and TempNew.TotalSalary=t.Salary;

Q-46. Write An SQL Query To Fetch Three Max Salaries From A


Table.
Ans.
The required query is:

SELECT distinct Salary from worker a WHERE 3 >= (SELECT count(distinct


Salary) from worker b WHERE a.Salary <= b.Salary) order by a.Salary desc;

Q-47. Write An SQL Query To Fetch Three Min Salaries From A


Table.
Ans.
The required query is:

SELECT distinct Salary from worker a WHERE 3 >= (SELECT count(distinct


Salary) from worker b WHERE a.Salary >= b.Salary) order by a.Salary desc;

Q-48. Write An SQL Query To Fetch Nth Max Salaries From A Table.
Ans.
The required query is:
SELECT distinct Salary from worker a WHERE n >= (SELECT count(distinct
Salary) from worker b WHERE a.Salary <= b.Salary) order by a.Salary desc;

Q-49. Write An SQL Query To Fetch Departments Along With The


Total Salaries Paid For Each Of Them.
Ans.
The required query is:

SELECT DEPARTMENT, sum(Salary) from worker group by DEPARTMENT;

Q-50. Write An SQL Query To Fetch The Names Of Workers Who


Earn The Highest Salary.
Ans.
The required query is:

SELECT FIRST_NAME, SALARY from Worker WHERE SALARY=(SELECT max(SALARY) from


Worker);

1. What is a JOIN clause?


Let's start with the basics: what is a JOIN clause, anyway? If you're familiar with
SQL, you've probably used JOINs extensively in the past. But using them is
different from being able to explain what they do — so let's go over a high-level
definition to start us off.

Simply put, a JOIN combines records from two separate tables. Oftentimes, we
come upon situations within SQL in which data on two separate tables is linked,
but separated. JOINs help bring that data back together.

Here's an example: let's say we have two tables in a database that tracks sales
from an e-commerce company. One table is called customers, and contains data
individual customers, like first_name and email. The second table is
called orders, and contains information on individual orders that have been
placed — like order_date and product.

Each order in our database is placed by a customer, but we don't keep the
customer's information within the orders table. Why not? Because if the same
customer placed multiple orders, and we kept track of customer information
within the orders table, we'd be duplicating data unnecessarily. By separating
customer information into its own customers table, we can reduce redundancy
and make updates and changes much easier to handle.

So, we include a field called customer_id within each record on the orderstable.
this ID is linked to a customer_id on the customers table, which contains non-
redundant data for each individual customer.

When we want to bring two tables together, we use a JOIN statement to combine
data as necessary.

Here's how these two tables might look in practice:

CREATE TABLE customers (


customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
);

CREATE TABLE orders (


order_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id INT NOT NULL,
order_placed_date DATE NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);

2. What are the different types of SQL JOIN clauses,


and how are they used?
In SQL, a JOIN clause is used to return a table that merges the contents of two or
more other tables together. For example, if we had two tables — one containing
information on Customers and another containing information on
the Orders various customers have placed — we could use a JOIN clause to bring
them together to create a new table: a complete list of orders by customer, with
all necessary information to make shipments.

There are multiple types of JOIN clauses, and they all serve slightly different
functions:

 INNER JOIN returns a list of rows for which there is a match in both tables
specified. It's the default join type, so if you just type JOIN without
specifying any other conditions, an INNER JOIN will be used.
 LEFT JOIN will return all results from the left table in your statement,
matched against rows in the right table when possible. If a row in the left
table does not contain a corresponding match in the right table, it will still
be listed — with NULL values in columns for the right table.
 RIGHT JOIN will return all results from the right table in your statement,
matched against rows in the left table when possible. If a row in the right
table does not contain a corresponding match in the left table, it will still be
listed — with NULL values in columns for the left table.
 FULL JOIN will return all results from both the left and the right tables in
your statement. If there are instances in which rows from the left table do
not match the right table or vice versa, all data will still be pulled in — but
SQL will output NULL values in all columns that are not matched.
 CROSS JOIN returns the Cartesian product of two tables — in other words,
each individual row of the left table matched with each individual row of the
right table.

3. What is the difference


between INNER JOIN and LEFT JOIN?
When constructing a SELECT query that combines two or more tables, choosing
the right JOIN type is half the battle. So how do we know when to use INNERJOIN,
and when to use the more complex variants like RIGHT JOIN and LEFTJOIN?

Simply put, INNER JOIN should be used when we want to exclude all records that
do not match both of the tables we're joining.

Let's check out an example of this: let's say that we have two tables — one
called students, and one called advisors. The students table contains a field
called advisor_id that references an id within the advisors table:
CREATE TABLE `advisors` (
`advisor_id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
PRIMARY KEY (`advisor_id`)
)

CREATE TABLE `students` (


`student_id` int(11) NOT NULL AUTO_INCREMENT,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`advisor_id` int(11) DEFAULT NULL,
PRIMARY KEY (`student_id`),
KEY `advisor_id` (`advisor_id`),
CONSTRAINT `students_ibfk_1` FOREIGN KEY (`advisor_id`) REFERENCES `advisors`
(`advisor_id`)
);

Here's the catch: not all students have an advisor, and not all advisors are
assigned to students:

SELECT * FROM students;

/*
+------------+------------+------------+------------+
| student_id | first_name | last_name | advisor_id |
+------------+------------+------------+------------+
| 1 | Tanisha | Blake | 2 |
| 2 | Jess | Goldsmith | NULL |
| 3 | Tracy | Wu | 3 |
| 4 | Alvin | Grand | 1 |
| 5 | Felix | Zimmermann | 2 |
+------------+------------+------------+------------+
5 rows in set (0.00 sec)
*/
SELECT * FROM advisors;
/*
+------------+------------+-----------+
| advisor_id | first_name | last_name |
+------------+------------+-----------+
| 1 | James | Francis |
| 2 | Amy | Cheng |
| 3 | Lamar | Alexander |
| 4 | Anita | Woods |
+------------+------------+-----------+
4 rows in set (0.00 sec)
*/

If we wanted to pull information on students and their advisors, excludingstudents


who are not assigned to an advisor, we would use an INNER JOIN:

SELECT s.first_name AS student_name, a.first_name AS advisor_name


FROM students AS s
INNER JOIN advisors AS a ON s.advisor_id = a.advisor_id;

/*
+--------------+--------------+
| student_name | advisor_name |
+--------------+--------------+
| Alvin | James |
| Tanisha | Amy |
| Felix | Amy |
| Tracy | Lamar |
+--------------+--------------+
4 rows in set (0.00 sec)
*/

Since we're using an INNER JOIN the results of this query exclude students for
whom the advisor_id is set to NULL. Let's take a look at what happens when we
use a LEFT JOIN instead:
SELECT s.first_name AS student_name, a.first_name AS advisor_name
FROM students AS s
LEFT JOIN advisors AS a ON s.advisor_id = a.advisor_id;

/*
+--------------+--------------+
| student_name | advisor_name |
+--------------+--------------+
| Alvin | James |
| Tanisha | Amy |
| Felix | Amy |
| Tracy | Lamar |
| Jess | NULL |
+--------------+--------------+
5 rows in set (0.01 sec)
*/

Notice that our data set now contains information on all students, even those for
whom the advisor is set to NULL!

4. What is the difference


between LEFT JOIN and RIGHT JOIN?
LEFT JOIN and RIGHT JOIN actually both do very similar things: they display the
results of a JOIN query including all records on a given table. The only difference
is that LEFT JOIN displays all records on the left table of the query,
and RIGHT JOIN displays all records on the right table!

To make this a bit clearer, let's use our example of students and advisors above:
a LEFT JOIN of students onto advisors will show a list of all students, even those
who do not have advisors — because students is the LEFT table:

SELECT s.first_name AS student_name, a.first_name AS advisor_name


FROM students AS s
LEFT JOIN advisors AS a ON s.advisor_id = a.advisor_id;

/*
+--------------+--------------+
| student_name | advisor_name |
+--------------+--------------+
| Alvin | James |
| Tanisha | Amy |
| Felix | Amy |
| Tracy | Lamar |
| Jess | NULL |
+--------------+--------------+
5 rows in set (0.01 sec)
*/

Notice that the advisor 'Anita' is excluded in the table above, because she is not
assigned to any students.

On the other hand, a RIGHT JOIN of students onto advisors will show a list of all
students who are assigned to advisors, plus a list of advisors not assigned to
students — because advisors is the RIGHT table:

SELECT s.first_name AS student_name, a.first_name AS advisor_name


FROM students AS s
RIGHT JOIN advisors AS a ON s.advisor_id = a.advisor_id;

/*
+--------------+--------------+
| student_name | advisor_name |
+--------------+--------------+
| Alvin | James |
| Tanisha | Amy |
| Felix | Amy |
| Tracy | Lamar |
| NULL | Anita |
+--------------+--------------+
5 rows in set (0.00 sec)
*/

Notice that the student 'Jess' is excluded in the table above, because she is not
assigned to an advisor.
5. How should data be structured to
facilitate JOINclauses in a one-to-many relationship?
Whta about a many-to-many relationship?
This one is a bit trickier, and is an interesting database design question.

Generally, one-to-many relationships are structured using a single FOREIGNKEY.


Consider our example of customers and orders above:

CREATE TABLE customers (


customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(255) NOT NULL,
last_name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
);

CREATE TABLE orders (


order_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
customer_id INT NOT NULL,
order_placed_date DATE NOT NULL,
FOREIGN KEY (customer_id) REFERENCES customers (customer_id)
);

This is a one-to-many relationship, because one customer can place


multiple orders, but one order cannot be assigned to more than one customer. As
such, we've defined it with a simple foreign key in the orders table pointing to a
given customer_id, and we can use JOIN clauses in our SELECT queries fairly
easily.

Many-to-many relationships are a bit more complicated. For example, what if we


had an orders table and a products table with a many-to-many relationship:
any order can contain multiple products, and any product can be assigned to
multiple orders. How would we structure our database?

The answer: we use an intermediary mapping table with two FOREIGN KEYs.
Consider the following:
CREATE TABLE orders (
order_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_placed_date DATE NOT NULL,
);

CREATE TABLE products (


product_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255) NOT NULL,
price INT NOT NULL
);

CREATE TABLE products_to_orders (


product_to_order_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
order_id INT NOT NULL,
product_id INT NOT NULL,
FOREIGN KEY (order_id) REFERENCES orders(order_id),
FOREIGN KEY (product_id) REFERENCES products(product_id)
);

Above, we've created a separate table called products_to_orders that maps


items on the products table to items on the orders table. Each row in
our products_to_orders table represents one product-order combination, so that
multiple products can be assigned to one order — and a single product can be
assigned to multiple orders.

In this example, we need to use two JOIN statements to link all these tables
together: one to link products_to_orders to products, and one to
link products_to_orders with orders.
Q. How do you list files in a directory?
ls – list directory contents
Q. How do you list all files in a directory, including the hidden files?
ls -a (-a, do not hide entries starting with.)
Q. How do you find out all processes that are currently running?
ps -f (-f does full-format listing.)
Q. How to copy file into directory?
cp /tmp/file_name . (dot mean in the current directory)
Q. How to remove directory with files?
rm -rfdirectory_name
Q. How do you find out the processes that are currently running or a particular user?
ps -au Myname (-u by effective user ID (supports names)) (a – all users)
Q. How do you kill a process?
The syntax for kill is

kill [signal or option] PID(s)

kill -9 8 (process_id 8) or kill -9 %7 (job number 7)


kill -9 -1 (Kill all processes you can kill.)
killall – kill processes by name most (useful – killall java)
Q. What would you use to view contents of the file?
The head Command
The head command displays the beginning of a file. The format of the head command is:
head <filename>
By default, you can only read the first ten lines of a file. You can change the number of lines
displayed by specifying a number option.
head -20 <filename>
The above command would display the first 20 lines of a file named <filename>.
The tail Command
The reverse of head is tail. Using tail, you can view the last ten lines of a file. This can be useful for
viewing the last ten lines of a log file for important system messages. You can also use tail to watch
log files as they are updated. Using the -f option, tail automatically prints new messages from an
open file to the screen in real-time. For example, to actively watch /var/log/messages, enter the
folowing at a shell prompt (as the root user):
tail -f /var/log/messages
Press [Ctrl]-[C] when you are finished.
The more Command
The more command is a “pager” utility used to view text in the terminal window one page or screen
at a time. The [Space] bar moves forward one page and [Q] quits.
Viewing Files with less
The format of the less command is:
less <filename>
The main difference between more and less is that less allows backward and single-line movement
using the same navigation as man pages: press the [Space] bar to go down one page, the [B] to go
back one page, the directional (or “arrow”) keys to move one line at a time, and [Q] to quit.
To search the output of a text file using less, press [/] and enter the keyword to search for within the
file.
/stuff
The above command would search through the file for all instances of “stuff” and highlight them in
the text.
Viewing and creating files with cat
The cat command is a versatile utility. It can be used to view text, to create text files, and to join files.
Its name is short for concatenate, which means to combine files.
Using cat alone echoes on the screen any text you enter. It will continue to do so until you exit with
the [Ctrl]-[D] keystroke.
Entering the cat command followed by a file name displays the entire contents of the file on the
screen. If the file is long, the contents scroll off the screen. You can control this by using the
redirection techiniques that are discussed in Section 4.9 Manipulating Information from the Shell.
The grep Command
The grep command is useful for finding specific character strings in a file. For example, to find every
reference made to “pattern” in the file <filename>, enter:
grep pattern <filename>
Each line in the file that includes the pattern “pattern” is located and displayed on the screen
Q. What would you use to edit contents of the file?
vi screen editor, gEditor, Nano Editor, Emacs Editor,
Q. What would you use to view contents of a large error log file?
tail -10 file_name ( last 10 rows)
Q. How do you log in to a remote Unix box?
Using telnet server_name or ssh -l ( ssh – OpenSSH SSH client (remote login program))
Q. How do you get help on a Linux terminal?
-h or –help
If you’re not sure how to use a specific command, run the command with the -h or –helpswitches.
You’ll see usage information and a list of options you can use with the command. For example, if
you want to know how to use the wget command, type wget –help or wget -h.
Q. How do you list contents of a directory including all of its subdirectories, providing full
details and sorted by modification time?
ls -lac
-a all entries
-c by time
Q. What is a filesystem?
Sum of all directories called file system.
A file system is the primary means of file storage in UNIX.
File systems are made of inodes and superblocks.
Q. How do you get its usage (a filesystem)?
By storing and manipulate files.
Q. How do you check for processes started by user ‘pat’?
ps -fu pat (-f -full_format u -user_name )
Q: Which command to remove or delete a file in your directory?
rm command is used to remove or delete a file in your directory.
Q: How do you add a user?
“adduser newuser” command will create a new general user called “newuser” on your system, and
to assign a password for the newuser account use “passwd newuser”.
Q. How do you start a job on background?
bg command is used to run the background job.
#bg%1 (job 1)
#bg%2 (job 2)
#bg%n (job n)
Note: In the same way fg command is used to run the foreground job
Q. What is the difference between internal and external commands?
Internal commands are stored in the; same level as the operating system while external
commands are stored on the hard disk among the other utility programs.
Q. List the three main parts of an operating system command:
The three main parts are the command, options and arguments.

Unix List of Basic Commands for QA and Test Engineer


Unix List of Basic Commands for QA and Test Engineer

File and directory listing Commands


$ ls command is used for directory and file listing with there permission.
$ ls -l list files in current directory.
$ ls -a list hidden files.

Directories commands
$ pwd -command is used for knowing user current working directory or you can say print working
directory.
$ cd - similar to DOS cd .it is use to change directory.
$ mkdir - use to create new directory.
$ rmdir - use to remove directory.

File Manipulation commands

$ cat filename - command is use to display file contents without paging.

$ cp source destination - command is use to copy file.


$ mv oldname newname - command is use to rename file .
$ rm filename - command use to delete file.
$ pico filename - command use to create or modify file.

$ More filename -List the contents of file pausing after each screen (press Space to continue listing).
$ grep string file-Search file for occurrences of string.
$ less filename - Display filename one screenful.A pager similar to (better than) more.

$ pg filename - View filename one screenfull at atime (a pager).


Special Control Characters
The control characters that have special meanings in a UNIX environment. Denoted by the
character ^ followed by a letter, each control character can be generated by holding down
Control and pressing the specified letter, then releasing both keys.
^c
Interrupt a process (applicable for most processes); used to halt a process immediately.
Pressing ^c, for example, enables you to stop the listing of a long file. However, if the file is very
long, there may be a noticeable time delay before the process is actually interrupted.
^d
Terminate a process; end-of-file marker (EOF). If a process does not have a clean termination
command and pressing ^c does not work, try pressing ^d.
^s

Suspend terminal output to your system. To resume terminal output, press ^q. ^s is usually referred
to as XON.
To view text a page at a time, use the more command.
^q
Resume terminal output suspended by pressing ^s (see above). ^q is usually referred to as XOFF.
^z
Suspend the foreground process, that is, place the current active program in a paused state.
Type the fg command to reactivate a process in the foreground. A foreground process will usually
keep control of your keyboard and terminal.
Type the bg command to reactivate a process in the background. A background process will let you
type other commands on the keyboard while it is running in a detached state.
^u
Erase command line.

^w
Erase previous word on a UNIX command line. A word is a string of characters separated by a
space or tab.

^r Retype current command line

OTHER COMMANDS
$ print file -Send file to the UNIX laser printer.
$ man command - Display information about command.
$ apropos keyword - List commands/programs that contain keyword in their description.
$ du - List the number of Kbytes for each directory below current working directory.
$ talk username - Interactively communicate with username; username has to be logged-in.
$ finger username - Find the username for username.
$ w - Display current activity on the system.
$ who - Show users that are currently logged-in.
$ tin - A program to read a collection of newsgroups (new articles arrive daily).
$ help [command] - If specified without command, a brief introduction is listed.If command is
specified, help displays the man page for command.
$ pine - Send email through the Internet
$ quota –v - Display disk usage and disk quota. This command does not display your email quota.
$ mydiskspace - Display uhunix disk usage only. This command does not display your email quota.
$ write username - Writes files or text to username.
$ !! - Repeats last command.

Process management
$ kill - Command use to terminate process.example: kill - 5555
$ nice program name - Command use to run program with lower priority.Recommended for running
background processes.

$ ps - Command use to list no of processes running in a system.


$ top - show (continuously) what process(es) is running.
https://www.softwaretestinghelp.com/interview-questions/top-20-most-important-jira-interview-
questions-and-answers/

Git task Notes Git commands

git config --global user.name "Sam Smith"


Tell Git Configure the
git config --global user.email sam@example.com
who you author name and
are email address to
be used with
your commits.
Note that
Git strips some
characters (for
example trailing
periods)
from user.name.

Create a git init


new local
repository

Check out Create a working git clone /path/to/repository


a copy of a local
repository repository:

For a remote git clone username@host:/path/to/repository


server, use:

Add files Add one or more git add <filename>


files to staging
git add *
(index):

Commit Commit changes git commit -m "Commit message"


to head (but not
yet to the remote
repository):

Commit any files git commit -a


you've added
with git add,
and also commit
any files you've
changed since
then:

Push Send changes to git push origin master


the master
branch of your
remote
repository:

Status List the files git status


you've changed
and those you
still need to add
or commit:

Connect If you haven't git remote add origin <server>


to a connected your
remote local repository
repository to a remote
server, add the
server to be able
to push to it:

List all currently git remote -v


configured
remote
repositories:

Branches Create a new git checkout -b <branchname>


branch and
switch to it:

Switch from one git checkout <branchname>


branch to
another:

List all the git branch


branches in your
repo, and also
tell you what
branch you're
currently in:
Delete the git branch -d <branchname>
feature branch:

Push the branch git push origin <branchname>


to your remote
repository, so
others can use it:

Push all branches git push --all origin


to your remote
repository:

Delete a branch git push origin :<branchname>


on your remote
repository:

Update Fetch and merge git pull


from the changes on the
remote remote server to
repository your working
directory:

To merge a git merge <branchname>


different branch
into your active
branch:

View all the git diff


merge conflicts: git diff --base <filename>
View the conflicts
against the base git diff <sourcebranch> <targetbranch>
file:

Preview changes,
before merging:

After you have git add <filename>


manually
resolved any
conflicts, you
mark the
changed file:
Tags You can use git tag 1.0.0 <commitID>
tagging to mark
a significant
changeset, such
as a release:

CommitId is the git log


leading
characters of the
changeset ID, up
to 10, but must
be unique. Get
the ID using:

Push all tags to git push --tags origin


remote
repository:

Undo If you mess up, git checkout -- <filename>


local you can replace
changes the changes in
your working
tree with the last
content in head:
Changes already
added to the
index, as well as
new files, will be
kept.

Instead, to drop git fetch origin


all your local
git reset --hard origin/master
changes and
commits, fetch
the latest history
from the server
and point your
local master
branch at it, do
this:
Search Search the git grep "foo()"
working directory
for foo():

https://www.guru99.com/agile-scrum-extreme-testing.html

Agile SDLC model is a combination of iterative and incremental process


models with focus on process adaptability and customer satisfaction by rapid
delivery of working software product. Agile Methods break the product into
small incremental builds. These builds are provided in iterations. Each
iteration typically lasts from about one to three weeks. Every iteration
involves cross functional teams working simultaneously on various areas like

 Planning

 Requirements Analysis

 Design

 Coding

 Unit Testing and

 Acceptance Testing.

At the end of the iteration, a working product is displayed to the customer


and important stakeholders.

What is Agile?
Agile model believes that every project needs to be handled differently and
the existing methods need to be tailored to best suit the project
requirements. In Agile, the tasks are divided to time boxes (small time
frames) to deliver specific features for a release.

Iterative approach is taken and working software build is delivered after each
iteration. Each build is incremental in terms of features; the final build holds
all the features required by the customer.

Here is a graphical illustration of the Agile Model −


The Agile thought process had started early in the software development and
started becoming popular with time due to its flexibility and adaptability.

The most popular Agile methods include Rational Unified Process (1994),
Scrum (1995), Crystal Clear, Extreme Programming (1996), Adaptive
Software Development, Feature Driven Development, and Dynamic Systems
Development Method (DSDM) (1995). These are now collectively referred to
as Agile Methodologies, after the Agile Manifesto was published in 2001.

Following are the Agile Manifesto principles −

 Individuals and interactions − In Agile development, self-organization and


motivation are important, as are interactions like co-location and pair
programming.

 Working software − Demo working software is considered the best means of


communication with the customers to understand their requirements, instead of
just depending on documentation.
 Customer collaboration − As the requirements cannot be gathered completely
in the beginning of the project due to various factors, continuous customer
interaction is very important to get proper product requirements.

 Responding to change − Agile Development is focused on quick responses to


change and continuous development.

Agile Vs Traditional SDLC Models


Agile is based on the adaptive software development methods, whereas
the traditional SDLC models like the waterfall model is based on a predictive
approach. Predictive teams in the traditional SDLC models usually work with
detailed planning and have a complete forecast of the exact tasks and
features to be delivered in the next few months or during the product life
cycle.

Predictive methods entirely depend on the requirement analysis and


planning done in the beginning of cycle. Any changes to be incorporated go
through a strict change control management and prioritization.

Agile uses an adaptive approach where there is no detailed planning and


there is clarity on future tasks only in respect of what features need to be
developed. There is feature driven development and the team adapts to the
changing product requirements dynamically. The product is tested very
frequently, through the release iterations, minimizing the risk of any major
failures in future.

Customer Interaction is the backbone of this Agile methodology, and open


communication with minimum documentation are the typical features of Agile
development environment. The agile teams work in close collaboration with
each other and are most often located in the same geographical location.

Agile Model - Pros and Cons


Agile methods are being widely accepted in the software world recently.
However, this method may not always be suitable for all products. Here are
some pros and cons of the Agile model.

The advantages of the Agile Model are as follows −

 Is a very realistic approach to software development.


 Promotes teamwork and cross training.

 Functionality can be developed rapidly and demonstrated.

 Resource requirements are minimum.

 Suitable for fixed or changing requirements

 Delivers early partial working solutions.

 Good model for environments that change steadily.

 Minimal rules, documentation easily employed.

 Enables concurrent development and delivery within an overall planned context.

 Little or no planning required.

 Easy to manage.

 Gives flexibility to developers.

The disadvantages of the Agile Model are as follows −

 Not suitable for handling complex dependencies.

 More risk of sustainability, maintainability and extensibility.

 An overall plan, an agile leader and agile PM practice is a must without which it
will not work.

 Strict delivery management dictates the scope, functionality to be delivered, and


adjustments to meet the deadlines.

 Depends heavily on customer interaction, so if customer is not clear, team can be


driven in the wrong direction.

 There is a very high individual dependency, since there is minimum


documentation generated.

 Transfer of technology to new team members may be quite challenging due to


lack of documentation.
STLC - Software Testing Life Cycle
Contrary to popular belief, Software Testing is not a just a single activity.

What is Software Testing Life Cycle (STLC)?


Software Testing Life Cycle (STLC) is defined as a sequence of activities conducted
to perform Software Testing.

It consists of series of activities carried out methodologically to help certify your


software product.

Diagram - Different stages in Software Test Life Cycle

Each of these stages have a definite Entry and Exit criteria; , Activities &
Deliverables associated with it.

What is Entry and Exit Criteria?


Entry Criteria:Entry Criteria gives the prerequisite items that must be completed
before testing can begin.

Exit Criteria: Exit Criteria defines the items that must be completed before testing
can be concluded

You have Entry and Exit Criteria for all levels in the Software Testing Life Cycle
(STLC)

In an Ideal world you will not enter the next stage until the exit criteria for the
previous stage is met. But practically this is not always possible. So for this tutorial,
we will focus on activities and deliverables for the different stages in STLC life cycle.
Lets look into them in detail.
Requirement Analysis
During this phase, test team studies the requirements from a testing point of view to
identify the testable requirements.

The QA team may interact with various stakeholders (Client, Business Analyst,
Technical Leads, System Architects etc) to understand the requirements in detail.

Requirements could be either Functional (defining what the software must do) or
Non Functional (defining system performance /security availability )

Automation feasibility for the given testing project is also done in this stage.

Activities

 Identify types of tests to be performed.


 Gather details about testing priorities and focus.
 Prepare Requirement Traceability Matrix (RTM).
 Identify test environment details where testing is supposed to be carried out.
 Automation feasibility analysis (if required).

Deliverables

 RTM
 Automation feasibility report. (if applicable)

Test Planning
Typically , in this stage, a Senior QA manager will determine effort and cost
estimates for the project and would prepare and finalize the Test Plan. In this phase,
Test Strategy is also determined.

Activities

 Preparation of test plan/strategy document for various types of testing


 Test tool selection
 Test effort estimation
 Resource planning and determining roles and responsibilities.
 Training requirement

Deliverables

 Test plan /strategy document.


 Effort estimation document.

Test Case Development


This phase involves creation, verification and rework of test cases & test
scripts. Test data , is identified/created and is reviewed and then reworked as well.

Activities

 Create test cases, automation scripts (if applicable)


 Review and baseline test cases and scripts
 Create test data (If Test Environment is available)

Deliverables

 Test cases/scripts
 Test data

Test Environment Setup


Test environment decides the software and hardware conditions under which a work
product is tested. Test environment set-up is one of the critical aspects of testing
process and can be done in parallel with Test Case Development Stage. Test
team may not be involved in this activity if the customer/development team
provides the test environment in which case the test team is required to do a
readiness check (smoke testing) of the given environment.

Activities

 Understand the required architecture, environment set-up and prepare


hardware and software requirement list for the Test Environment.
 Setup test Environment and test data
 Perform smoke test on the build

Deliverables

 Environment ready with test data set up


 Smoke Test Results.

Test Execution
During this phase the testers will carry out the testing based on the test plans and
the test cases prepared. Bugs will be reported back to the development team for
correction and retesting will be performed.

Activities

 Execute tests as per plan


 Document test results, and log defects for failed cases
 Map defects to test cases in RTM
 Retest the Defect fixes
 Track the defects to closure

Deliverables

 Completed RTM with execution status


 Test cases updated with results
 Defect reports

Test Cycle Closure


Testing team will meet , discuss and analyze testing artifacts to identify strategies
that have to be implemented in future, taking lessons from the current test cycle.
The idea is to remove the process bottlenecks for future test cycles and share best
practices for any similar projects in future.

Activities

 Evaluate cycle completion criteria based on Time,Test


coverage,Cost,Software,Critical Business Objectives , Quality
 Prepare test metrics based on the above parameters.
 Document the learning out of the project
 Prepare Test closure report
 Qualitative and quantitative reporting of quality of the work product to the
customer.
 Test result analysis to find out the defect distribution by type and severity.

Deliverables

 Test Closure report


 Test metrics

Finally, summary of STLC Phases along with Entry and Exit Criteria
STLC Stage Entry Criteria Activity Exit Criteria Deliverables

Requirement Requirements Analyse business functionality to Signed off RTM RTM


Analysis Document available know the business modules and
(both functional and module specific functionalities. Test automation Automation
non functional) feasibility report feasibility report
Identify all transactions in the signed off by the (if applicable)
Acceptance criteria modules. client
defined.
Identify all the user profiles.
Application
architectural Gather user interface/
document available. authentication, geographic spread
requirements.

Identify types of tests to be


performed.

Gather details about testing


priorities and focus.

Prepare RequirementTraceability
Matrix (RTM).

Identify test environment details


where testing is supposed to be
carried out.

Automation feasibility analysis (if


required).

Test Planning Requirements Analyze various testing approaches Approved test Test
Documents available plan/strategy plan/strategy
document. document.
Requirement Finalize on the best suited approach
Traceability matrix. Effort estimation Effort estimation
Preparation of test plan/strategy document signed document.
Test automation document for various types of off.
feasibility document. testing

Test tool selection

Test effort estimation


STLC Stage Entry Criteria Activity Exit Criteria Deliverables

Resource planning and determining


roles and responsibilities.

Test case Requirements Create test cases, test design, Reviewed and Test
development Documents automation scripts (where signed test cases/scripts
applicable) Cases/scripts
RTM and test plan Test data
Review and baseline test cases and Reviewed and
Automation analysis scripts signed test data
report
Create test data

Test Environment System Design and Understand the required Environment setup Environment
setup architecture architecture, environment set-up is working as per ready with test
documents are the plan and data set up
available Prepare hardware and software checklist
development requirement list Smoke Test
Environment set-up Test data setup is Results.
plan is available Finalize connectivity requirements complete

Prepare environment setup Smoke test is


checklist successful

Setup test Environment and test


data

Perform smoke test on the build

Accept/reject the build depending


on smoke test result

Test Execution Baselined RTM,Test Execute tests as per plan All tests planned Completed RTM
Plan , Test case/scripts are executed with execution
are available Document test results, and log status
defects for failed cases Defects logged and
Test environment is tracked to closure Test cases
ready Update test plans/test cases, if updated with
necessary results
Test data set up is
done Map defects to test cases in RTM Defect reports

Unit/Integration test Retest the defect fixes

Regression Testing of application


STLC Stage Entry Criteria Activity Exit Criteria Deliverables

report for the build to


be tested is available Track the defects to closure

Test Cycle closure Testing has been Evaluate cycle completion criteria Test Closure
completed based on - Time,Test coverage , Cost report signed off
, Software Quality , Critical Business by cli
Test results are Objectives
available
Prepare test metrics based on the
Defect logs are above parameters.
available
Document the learning out of the
project

Prepare Test closure report

Qualitative and quantitative


reporting of quality of the work
product to the customer.

Test result analysis to find out the


defect distribution by type and
severity

How to Create Requirements Traceability Matrix (RTM)


What is Traceability Matrix?(TM)
A Traceability Matrix is a document that co-relates any two-baseline documents that
require a many-to-many relationship to check the completeness of the relationship.

It is used to track the requirements and to check the current project requirements
are met.
What is RTM (Requirement Traceability Matrix)?
Requirement Traceability Matrix or RTM captures all requirements proposed by the
client or software development team and their traceability in a single document
delivered at the conclusion of the life-cycle.

In other words, it is a document that maps and traces user requirement with test
cases. The main purpose of Requirement Traceability Matrix is to see that all test
cases are covered so that no functionality should miss while doing Software testing.

Requirement Traceability Matrix – Parameters include

 Requirement ID
 Risks
 Requirement Type and Description
 Trace to design specification
 Unit test cases
 Integration test cases
 System test cases
 User acceptance test cases
 Trace to test script

Types of Traceability Test Matrix


 Forward traceability: This matrix is used to check whether the project
progresses in the desired direction and for the right product. It makes sure
that each requirement is applied to the product and that each requirement is
tested thoroughly. It maps requirements to test cases.

 Backward or reverse traceability: It is used to ensure whether the current


product remains on the right track. The purpose behind this type of traceability
is to verify that we are not expanding the scope of the project by adding code,
design elements, test or other work that is not specified in the requirements. It
maps test cases to requirements.

 Bi-directional traceability ( Forward+Backward): This traceability matrix


ensures that all requirements are covered by test cases. It analyzes the
impact of a change in requirements affected by the Defect in a work product
and vice versa.

How to create Requirement Traceability Matrix


Let's understand the concept of Requirement Traceability Matrix through a Guru99
banking project.

On the basis of Business Requirement Document (BRD) and Technical


Requirement Document (TRD), testers start writing test cases.

Let suppose, the following table is our Business Requirement Document


or BRD for Guru99 banking project.

Here the scenario is that the customer should be able to login to Guru99 banking
website with the correct password and user#id while manager should be able to
login to the website through customer login page.

While the below table is our Technical Requirement Document (TRD).


Note: QA teams do not document the BRD and TRD. Also some companies
use Function Requirement Documents (FRD) which are similar to Technical
Requirement Document but the process of creating Traceability Matrix remains the
same.

Let's Go Ahead and create RTM Testing

Step 1: Our Test Case is

"Verify Login, when correct ID and Password is entered, it should login successfully"

Step 2: Identify the Technical Requirement that this test case is verifying. For our
test case, the technical requirement is T94 is being verified.
Step 3: Note this Technical Requirement (T94) in the Test Case.

Step 4: Identify the Business Requirement for which this TR (Technical


Requirement-T94) is defined

Step 5: Note the BR (Business Requirement) in Test Case

Step 6: Do above for all Test Cases. Later Extract the First 3 Columns from your
Test Suite. RTM in testing is Ready!
Advantage of Requirement Traceability Matrix
 It confirms 100% test coverage
 It highlights any requirements missing or document inconsistencies
 It shows the overall defects or execution status with a focus on business
requirements
 It helps in analyzing or estimating the impact on the QA team's work with
respect to revisiting or re-working on the test cases

Anda mungkin juga menyukai