query to select topic with highest number of comment +support+oppose+views

Posted by chetan on Programmers See other posts from Programmers or by chetan
Published on 2012-11-07T01:56:09Z Indexed on 2012/11/07 5:14 UTC
Read the original article Hit count: 250

Filed under:
|
|

table schema

title      description    desid    replyto    support    oppose   views
browser    used           a1        none        1          1       12
-          bad topic      b2        1           2          3       14
sql        database       a3        none        4          5       34
-          crome          b4        1           3          4       12

Topic desid starts with a and comment desid starts with b .For comment replyto is the desid of topic . Its easy to select * with highest number of support+oppose+views by query "select * from [DB_user1212].[dbo].[discussions] where desid like 'a%' order by (sup+opp+visited) desc"

For highest (comment +support+oppose+views ) i tried "select * from [DB_user1212].[dbo].[discussions] where desid like 'a%' order by ((select count(*) from [DB_user1212].[dbo].[discussions] where replyto = desid )+sup+opp+visited) desc" but it didn't work . Because its not possible to send desid from outer query to innner subquery .

© Programmers or respective owner

Related posts about database

Related posts about sql