| Author |
Topic |
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-30 : 10:09:03
|
| Hi Friends,These are the tables A,B,CA table had columns Articleid ,userid and ArticleNameB table had Columns Comments ,Articleid and useridc table had Columns voting ,Articleid and useridi need your help to select Articleid,ArticleName ,Comments,no of Comments ,Voting for that particular userid |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-30 : 10:14:03
|
quote: Originally posted by Moo Hi Friends,These are the tables A,B,CA table had columns Articleid ,userid and ArticleNameB table had Columns Comments ,Articleid and useridc table had Columns voting ,Articleid and useridi need your help to select Articleid,ArticleName ,Comments,no of Comments ,Voting for that particular userid
your result can be achieved by simply joining the tables involved on related columns and aggregating to find count. Try it out yourself and post if you face any difficulty. |
 |
|
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-30 : 10:23:14
|
| But i cant get the comments for that particular article |
 |
|
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-30 : 10:30:16
|
| select top 10 e.Articleid ,e.Articlename ,r.Voting ,n.comments,count(n.Articlecommentsid)as noofcomments from A e join B n on e.Articleid=c.Articleid join C r on e.Articleid=r.Articleid where e.deleted=0 and e.userid=27group by e.Articleid,e.Articlename, r.Voting,n.commentsorder by e.Articleid desc |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-30 : 10:49:50
|
| [code]SELECT a.Articleid,a.ArticleName,b.Comments,t.cmntcnt,c.votingFROM A aINNER JOIN B bON b.Articleid=a.,ArticleidAND b.userid=a.useridINER JOIN C cON c.Articleid=a.,ArticleidAND c.userid=a.useridINNER JOIN (SELECT Articleid,userid,COUNT(Comments) AS cmntcnt FROM B GROUP BY Articleid,userid)tON t.Articleid=a.,ArticleidAND t.userid=a.userid[/code] |
 |
|
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-30 : 11:13:09
|
| Here i am getting the Articleid,ArticleName,Comments and No of comments ,rating but the ArticleName should not be repeated |
 |
|
|
Cowboy
Yak Posting Veteran
72 Posts |
Posted - 2008-07-30 : 12:24:12
|
| Group by ArticleName perhaps?I want to build a spaceship with ligthspeed capabilities and I don't even know what a wrench is. |
 |
|
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-30 : 12:29:08
|
| Then too i can't get the Correct answer |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-30 : 13:14:24
|
quote: Originally posted by Moo Here i am getting the Articleid,ArticleName,Comments and No of comments ,rating but the ArticleName should not be repeated
how can you get unique values of ArticleName & id when you've more than 1 comments existing for them?Alternatively if you want only 1 record per articlke, then which comment value do you want to show for them as you can show only single value. or do you want to combine all comments and return as a single value? |
 |
|
|
Moo
Starting Member
10 Posts |
Posted - 2008-07-31 : 01:12:50
|
| I need to combine all comments and return as a single value |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-07-31 : 01:22:52
|
Post 1. your table DDL in terms of CREATE TABLE . . .2. some sample data in terms of INSERT INTO table . . .3. and also the expected result KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|