0
Select Count(*),* from TourBooking Where MemberID = 6 

Giving an error

"Column 'TourBooking.ID' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause."

frlan
  • 6,950
  • 3
  • 31
  • 72
Mike
  • 751
  • 2
  • 10
  • 25

3 Answers3

2

You need to use a subselect:

Select (select Count(*) from TourBooking Where MemberID = 6), * 
    from TourBooking 
Where MemberID = 6
Christian Barron
  • 2,695
  • 1
  • 14
  • 22
2

count() is an aggregate function and thus requires a group by. If you want to count the total number of rows in your result, you can use a window function to add such a column:

select count(*) over () as total_count, 
       TourBooking.*
from TourBooking
where MemberID = 6;

If you want the total count in the table TourBooking regardless of the value in the column MemberId you need a scalar sub-query in order to retrieve the count:

Select (select Count(*) from TourBooking) as total_count,
       TourBooking.*
from TourBooking 
where MemberID = 6 
-2

Please change your code from

Select Count(*),* from TourBooking Where MemberID = 6 

into

Select Count(*) from TourBooking Where MemberID = 6
whywhy
  • 97
  • 7
  • don't use code snippets for sql, just use 4 spaces at the start or use the code sample button `{}` – Tanner Feb 10 '15 at 09:38