Hi
I have this table

name age

John 14
Katy 14
Mark 15

and I want the number of rows where the age is equal to 14 , so in this example the result should be (2)
but my problem is that I dont know how to start , so can any one help ne with that please

Simple SQL statement

SELECT name,COUNT(age) as AGECOUNT FROM table WHERE age = 14

You can try this,

Select name,COUNT(age) as AGECOUNT FROM table WHERE age=14 Group By name;

Hi,
Remove column name from SELECT; this is correct form:

SELECT COUNT(age) as AGECOUNT FROM table WHERE age=14;

You can add any other columns you want, and that has already been posted 3 times. I don't think there is any need for the group by clause because there will be only one result row.

If you add any other column like name in below query ,than its not working without group by.
SELECT name,COUNT(age) as AGECOUNT FROM table WHERE age = 14

That is correct to remove name from query than it will work without group by clause

commented: thank for the correction +14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.