DB2 Interview Questions and Answers:Part 1
1) How would you find out the total number of rows in a DB2 table?
Use SELECT COUNT(*) ... in db2 query
2) How do you eliminate duplicate values in DB2 SELECT?
Use SELECT DISTINCT ... in db2 query
3) How do you select a row using indexes in DB2?
Specify the indexed columns in the WHERE clause of db2 query.
4) How do you find the maximum value in a column in db2?
Use SELECT MAX(...) .. in db2 query
5) How do you retrieve the first 5 characters of FIRSTNAME column of DB2 table EMP ?
SQL Query : SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;
6) What are aggregate functions?
Bulit-in mathematical functions for use in SELECT clause.
7) Can you use MAX on a CHAR column?
YES.
8) My SQL statement SELECT AVG(SALARY) FROM EMP yields inaccurate results. Why?
Because SALARY is not declared to have NULLs and the employees for whom the salary is not known are also counted.
9) How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a complete name?
SELECT FIRSTNAME ‘ ‘ LASTNAME FROM EMP;
10) What is the use of VALUE function?
1. Avoid -ve SQLCODEs by handling nulls and zeroes in computations
2. Substitute a numeric value for any nulls used in computation
11) What is UNION,UNION ALL? –
UNION : eliminates duplicates
UNION ALL: retains duplicates
Both these are used to combine the results of different SELECT statements.
Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how many times should I specify UNION to eliminate the duplicate rows? -
Once.
12) What is the restriction on using UNION in embedded SQL?
It has to be in a CURSOR.
13) In the WHERE clause what is BETWEEN and IN? –
BETWEEN supplies a range of values while IN supplies a list of values.
14) Is BETWEEN inclusive of the range values specified? –
Yes.
15) What is 'LIKE' used for in WHERE clause? What are the wildcard characters? –
LIKE is used for partial string matches. ‘%’ ( for a string of any character ) and ‘_’ (for any single character ) are the two wild card characters.
16) When do you use a LIKE statement?
To do partial search e.g. to search employee by name, you need not specify the complete name; using LIKE, you can search for partial string matches.
17) What is the meaning of underscore ( ‘_’ ) in the LIKE statement? –
Match for any single character.
18) What do you accomplish by GROUP BY ... HAVING clause? –
GROUP BY partitions the selected rows on the distinct values of the column on which you group by.
HAVING selects GROUPs which match the criteria specified
19) Consider the employee table with column PROJECT nullable. How can you get a list of employees who are not assigned to any project?
SELECT EMPNO
FROM EMP
WHERE PROJECT IS NULL;
1) How would you find out the total number of rows in a DB2 table?
Use SELECT COUNT(*) ... in db2 query
2) How do you eliminate duplicate values in DB2 SELECT?
Use SELECT DISTINCT ... in db2 query
3) How do you select a row using indexes in DB2?
Specify the indexed columns in the WHERE clause of db2 query.
4) How do you find the maximum value in a column in db2?
Use SELECT MAX(...) .. in db2 query
5) How do you retrieve the first 5 characters of FIRSTNAME column of DB2 table EMP ?
SQL Query : SELECT SUBSTR(FIRSTNAME,1,5) FROM EMP;
6) What are aggregate functions?
Bulit-in mathematical functions for use in SELECT clause.
7) Can you use MAX on a CHAR column?
YES.
8) My SQL statement SELECT AVG(SALARY) FROM EMP yields inaccurate results. Why?
Because SALARY is not declared to have NULLs and the employees for whom the salary is not known are also counted.
9) How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a complete name?
SELECT FIRSTNAME ‘ ‘ LASTNAME FROM EMP;
10) What is the use of VALUE function?
1. Avoid -ve SQLCODEs by handling nulls and zeroes in computations
2. Substitute a numeric value for any nulls used in computation
11) What is UNION,UNION ALL? –
UNION : eliminates duplicates
UNION ALL: retains duplicates
Both these are used to combine the results of different SELECT statements.
Suppose I have five SQL SELECT statements connected by UNION/UNION ALL, how many times should I specify UNION to eliminate the duplicate rows? -
Once.
12) What is the restriction on using UNION in embedded SQL?
It has to be in a CURSOR.
13) In the WHERE clause what is BETWEEN and IN? –
BETWEEN supplies a range of values while IN supplies a list of values.
14) Is BETWEEN inclusive of the range values specified? –
Yes.
15) What is 'LIKE' used for in WHERE clause? What are the wildcard characters? –
LIKE is used for partial string matches. ‘%’ ( for a string of any character ) and ‘_’ (for any single character ) are the two wild card characters.
16) When do you use a LIKE statement?
To do partial search e.g. to search employee by name, you need not specify the complete name; using LIKE, you can search for partial string matches.
17) What is the meaning of underscore ( ‘_’ ) in the LIKE statement? –
Match for any single character.
18) What do you accomplish by GROUP BY ... HAVING clause? –
GROUP BY partitions the selected rows on the distinct values of the column on which you group by.
HAVING selects GROUPs which match the criteria specified
19) Consider the employee table with column PROJECT nullable. How can you get a list of employees who are not assigned to any project?
SELECT EMPNO
FROM EMP
WHERE PROJECT IS NULL;