The largest Interview Solution Library on the web

Interview Questions
« Previous | 0 | 1 | 2 | 3 | 4 | Next »

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 ?


6.What are aggregate functions?

Bulit-in mathematical functions for use in SELECT clause.

7.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.

8.How do you concatenate the FIRSTNAME and LASTNAME from EMP table to give a complete name?


9.What is the use of VALUE function?

  • Avoid -ve SQLCODEs by handling nulls and zeroes in computations
  • Substitute a numeric value for any nulls used in computation

10. 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.

11.What is the restriction on using UNION in embedded SQL?

It has to be in a CURSOR.

12.In the WHERE clause what is BETWEEN and IN? –

BETWEEN supplies a range of values while IN supplies a list of values.

13.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.

14.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.

15.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

16.Consider the employee table with column PROJECT nullable. How can you get a list of employees who are not assigned to any project?


17.What is the result of this query if no rows are selected:


18.Why SELECT * is not preferred in embedded SQL programs?

For three reasons:
If the table structure is changed ( a field is added ), the program will have to be modified
Program might retrieve the columns which it might not use, leading on I/O over head.
The chance of an index only scan is lost.

19.What are correlated subqueries?

A subquery in which the inner ( nested ) query refers back to the table in the outer query. Correlated subqueries must be evaluated for each qualified row of the outer query that is referred to.

20.What is a cursor? why should it be used?

Cursor is a programming device that allows the SELECT to find a set of rows but return them one at a time.
Cursor should be used because the host language can deal with only one row at a time.

« Previous | 0 | 1 | 2 | 3 | 4 | Next »

copyright © 2014 - all rights riserved by