HI,

Am new to PL\SQL. I just want to fetch the 4 fields from employee table. how to do it?

employee_ID, First_name, Last_name, total number of employees from employee table.

i tried to fetch using count() function. but it is not giving the total number of employees.

can anyone please help me?

Thank you.

Recommended Answers

All 2 Replies

select count(*) from employee

I assumed your 'total number of employees' is not stored in database.
You cannot join all these into one query except your employee_ID, First_name, Last_name can be duplicated. For example: if we got 3 rows of employee_ID of 'ID1' and 2 rows of employee_ID of 'ID2', then I will use this query:
SELECT employee_ID,First_name,Last_name,count(employee_ID) FROM employee GROUP BY employee_ID
this will result in:

employee_ID First_name Last_name count(employee_ID)
---------------------------------------------------
ID1         Lau        PS        3
ID2         Clark      Kent      2

while if it cannot be duplicated, means all the count will be value '1'. In this case, what I normally done is with 2 ways:
1. like @JerrimePatient suggested, use 1 query for select 3 data and seperate another query for count(*).
2. Use 1 query for select 3 data(except count) then using the program to count the rows of data retrieved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.