Find the count of members who have made at least one booking

Question

Find the total number of members (including guests) who have made at least one booking.

Expected Results

count
30

Your Answer

Your Results

Loading database...

Answers and Discussion

select count(distinct memid) from cd.bookings

Your first instinct may be to go for a subquery here. Something like the below:

select count(*) from 
	(select distinct memid from cd.bookings) as mems

This does work perfectly well, but we can simplify a touch with the help of a little extra knowledge in the form of COUNT DISTINCT. This does what you might expect, counting the distinct values in the passed column.