![]() |
| ||
| SQL Query question over multiple tables Hey all, Ok first my problem. I have a database that has an employee table and then also an absent table(for when they are off sick). The problem i have is using sql to find the employee that is off the most! So for my sql on the absent table i do something like this select EMPLOYEEID, count(*) from ABSENCEHISTORY group by EMPLOYEEID having count(*)>= ALL(select count(*) from ABSENCEHISTORY group by EMPLOYEEID); and this gives EMPLOYEEID COUNT(*) Now this is all good as i now know that the employee with id 2 has had the most absences. However is it possible in 1 query to use the EMPLOYEEID i have been given there to find out the attributes of the employee that are stored in the EMPLOYEE table. I have been trying JOINS, UNIONS but no success as far. Does anyone know if it is actually possible to do this in 1 query? I have also tried this select max(count(*)) from ABSENCEHISTORY group by EMPLOYEEID; which gives MAX(COUNT(*)) But that doesn't help much as i have nothing about which employeeid it corresponds to! Just the highest value! Thank-you DJ CLipz |
| ||
| Re: SQL Query question over multiple tables also find out the employee id and pas that employee id to outer query to find out all the other details. |
| ||
| Re: SQL Query question over multiple tables Not the best solution but... SELECT * FROM EMPLOYEE You should take into account that there may be more than one person with the worst attendance. Nige |
| ||
| Re: SQL Query question over multiple tables Quote:
How about a slight modification on that theme: SELECT Z.Absences, E.* FROM EMPLOYEE |
| ||
| Re: SQL Query question over multiple tables Unfortunately Select top n isn't supported by Oracle. Nige |
| ||
| Re: SQL Query question over multiple tables Quote:
Nige, Sorry about that. I am not currently working with Oracle but, rather, with SQL Server (and my next most recent experience is on Teradata which also supports the TOP n feature) so I am not sure how to immulate the TOP n functionality in Oracle. I am, however, quite sure that there is a means for doing so. |
| All times are GMT -4. The time now is 11:20 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC