DBA > Job Interview Questions > DERBY Java Database FAQs

SQL Tips - Tricks of the VALUES Clause - Mapping

More DBA job interview questions and answers at http://dba.fyicenter.com/Interview-Questions/

(Continued from previous question...)

SQL Tips - Tricks of the VALUES Clause - Mapping Column Values to Return Values

Multiple-row VALUES tables are useful in mapping column values to desired return values in queries:

-- get the names of all departments in Ohio
SELECT DeptName
FROM Depts,
(VALUES (1, 'Shoe'),
(2, 'Laces'),
(4, 'Polish'))
AS DeptMap(DeptCode,DeptDesc)
WHERE Depts.DeptCode = DeptMap.DeptCode
AND Depts.DeptLocn LIKE '%Ohio%'

You might also find it useful to store values used often for mapping in a persistent table and then using that table in the query.

(Continued on next question...)

Other Job Interview Questions