Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> -> Help me w/this built-in function!
I'm new to Oracle (but not new to SQL databases) and wonder...why can't I do the following with the DECODE() function?:
select e.id e.lastname, e.firstname decode((select count(*) from qualifications q where q.id = e.id),3,'Qualified','Not Qualified') from employee e
I want the following and if the employee has three entries in the qualifications table, then I want the phrase 'Qualified' and if not, the 'Not Qualified':
id lastname firstname ------- --------------- -------------- -------------- 123 Smith Jim Not Qualified 765 Doe John Qualified 444 Garner Debbit Qualified 231 Smith Robin Not Qualified 885 Lopez Rick Not Qualified
The SQL statement won't work as constructed above. Is it that the expression "select count(*)..." is a complex expression? It works for a simple expression, such as when specifying a column name. It even works with a "simplified" complex expression, such as "2 + 1". In this case the "Qualified" gets displayed. If I put "5 + 1" then "Not Qualified" is displayed. This is correct...but what about a complex expression like a sub-query?
Thanks in advance!
-- Les Gainous, lesgainous_at_earthlink.net Visit my web page at http://home.earthlink.net/~lesgainous Looking for a Client-Server job in California? http://home.earthlink.net/~lesgainous/jobs.htmlReceived on Fri Oct 18 1996 - 00:00:00 CDT
![]() |
![]() |