Kram143
Kram143

Reputation: 1

Count the foreign key present on a table regardless of their appearances

i have a table name attendance with this following record. I want to count how many foreign key are there regardless of the number of appearances.

attendance id | empnumber(foreign key)|   date   |   type   |  time  |
1               399388                 2016-02-18  time in   10:00:00
2               399388                 2016-02-18  break out 12:00:00
3               399388                 2016-02-18  break in  13:00:00 
4               399388                 2016-02-18  time out  19:00:00                 
5               65429                  2016-02-18  time in   08:00:00
6               65429                  2016-02-18  break out 12:00:00
7               65429                  2016-02-18  break in  13:00:00
8               65429                  2016-02-18  time out  17:00:00

There is a two empnumber in a record.. I want to return how many empnumber the record contains regardless of their appearances.

In this case the query must return two rows not 8 rows. Thanks in advance for the help..

Upvotes: 0

Views: 39

Answers (1)

Shoaib Raza
Shoaib Raza

Reputation: 61

select count(distinct empnumber) from attendance

Upvotes: 1

Related Questions