how to query this ??

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

how to query this ??

Post by PHPycho »

Hello forums !!
I would like to know how to count the no of fields that has specific values.
for example:
"table1" has field called "filed1" and it has values
------
|field1|
-------
|X |
|X |
|Y |
| X |
:
:
etc
I would like to know the no of rows that has the value X using count...
How to perform such query..
thanks in advance to all of you
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Code: Select all

SELECT COUNT(*) AS da_total FROM da_table WHERE da_field='x'
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

Pardon me
Cant we do without using where condition, ie what i want
Thanks again
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

If you don't like WHERE you can HAVING :)
But if we talking seriously what problems with WHERE?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

If you want to calculate the count for each respective value, you can use the GROUP BY clause
Post Reply