By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

Counting rows part II

P: 14
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
Share this Question
Share on Google+
3 Replies


debasisdas
Expert 5K+
P: 8,127
Is it such that for the same products.name you have different products.altname ?
Apr 14 '08 #2

P: 14
Is it such that for the same products.name you have different products.altname ?
Yes, that is correct.

/Chris
Apr 14 '08 #3

ck9663
Expert 2.5K+
P: 2,878
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.