user1680323
user1680323

Reputation: 9

Counting a SQL result

I select data with group by

select rkey from asset group by rkey

this will give me:

 ADATUM 
 BEZ1
 KLASSE
 AWERT
 ANLNR
 LOCATION
 BEZ2
 BKRS
 UNR

now, how can I count the result, so that I get (9). If it works, in one SELECT Statement.

Upvotes: 0

Views: 2180

Answers (2)

Mahmoud Gamal
Mahmoud Gamal

Reputation: 79929

SELECT COUNT(rkey)
FROM
(
  select rkey from asset group by rkey
) t

Or, you can get rid of the GROUP BY and use DISTINCT instead, because the inner query with select rkey from asset group by rkey is acting like DISTINCT. So you can do it in one query:

SELECT COUNT(DISTINCT rkey) 
FROM asset

Upvotes: 4

Robert
Robert

Reputation: 25753

You can try to use distinct

select count(distinct rkey) 
from asset 

Upvotes: 1

Related Questions