Counting in a MySQL DB

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
andrei.mita
Forum Commoner
Posts: 65
Joined: Sun May 08, 2005 4:06 am
Location: Barlad/Romania

Counting in a MySQL DB

Post by andrei.mita »

Hello,

I don't really know how to explain what I need but here is an example. Hope you can understand and can give me some tips.
I have a 5 records db.

ID shop_name cards pos_id
1 shop1 CA PS01
2 shop1 CA PS02
3 shop2 CF PS03
4 shop2 CA PS04
5 shop3 CF PS05

The actual db has around 5000 records and 12 fields but if I can sort it for this example is more the enough. Here is what I want to do: I want to see how many pos I have that accept CA cards. This is simple. How do I see how many shops I have that accept CA cards? The only thing I thought to do is to sort the db by shop name and the compare a record with the next one. Is this the only way? Will this method slow down the server a lot? There will be around 5 users performing reports like this on the 5000 records db. Thanks.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Code: Select all

SELECT count(distinct shop_name) FROM xyz WHERE cards='CA'
andrei.mita
Forum Commoner
Posts: 65
Joined: Sun May 08, 2005 4:06 am
Location: Barlad/Romania

Post by andrei.mita »

perfect for what I need. thank you very much.
Post Reply