469,330 Members | 1,280 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

Counting rows part II

Hi,
I have the following query:
1. SELECT products.name, COUNT(reviews.review)
2. FROM (select distinct name from products) products
3. FULL JOIN reviews ON products.name = reviews.productname
4. GROUP BY products.name
which lists product names and the number of reviews for each product. I need to include one more column from the products table in the table resulting from the above query. This column (called altname) can have different values for a certain product (each product can appear multiple times in the table). It doesn't matter which of the altname values for a product that is presented in the resulting table as long as someone is. Is this possible? See example below.
The products table:
products.name products.altname
ProdA prd_a
ProdA proda
ProdB prb
ProdB prodb

...and the review table:
reviews.prodname review
ProdA bla bla....
ProdA bla bla....
ProdB bla bla....

should result in:
name altname reviews_count
ProdA prd_a 2
ProdB prb 1

/Chris
Apr 14 '08 #1
3 1006
debasisdas
8,127 Expert 4TB
Is it such that for the same products.name you have different products.altname ?
Apr 14 '08 #2
Is it such that for the same products.name you have different products.altname ?
Yes, that is correct.

/Chris
Apr 14 '08 #3
ck9663
2,878 Expert 2GB
You might want to reconsider re-designing your tables and their relationship.

-- CK
Apr 14 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by walexand | last post: by
1 post views Thread by Tony Johansson | last post: by
3 posts views Thread by Megan | last post: by
18 posts views Thread by ChadDiesel | last post: by
3 posts views Thread by nickels | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.