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,698
  • 3
  • 26
  • 70
Mike
  • 729
  • 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,540
  • 1
  • 11
  • 20
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 
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
-2

Please change your code from

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

into

Select Count(*) from TourBooking Where MemberID = 6
a_horse_with_no_name
  • 497,550
  • 91
  • 775
  • 843
whywhy
  • 97
  • 6
  • 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