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.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?
SELECT FIRSTNAME || ‘ ‘ ||
LASTNAME FROM EMP; 9.What is the use of VALUE function?
10. What is UNION,UNION ALL?UNION : eliminates duplicates 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. 16.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 17.What is the result of this query if no rows are selected:SELECT SUM(SALARY) 18.Why SELECT * is not preferred in embedded SQL programs?For three reasons: 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. |