Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

sql query

i have table thread(tblthread) which has following colmns(Thread_Id,Forun_Id,Thread_Topic,Thread_Description)

in my Forums.aspx in data grid i want to display number of threads in each forum,like

Forums Threads

forum1 10

forum2 22

what sqlquery i have to write,iam little bit confused

how to get count of threads in each forum.
[400 byte] By [syedwna] at [2007-11-11 10:31:59]
# 1 Re: sql query
Select Forum_Id,SUM(Forum_Id)
From tblthread
Group by Forum_Id

http://www.programmingknowledge.com/
postmaster at 2007-11-11 23:11:45 >
# 2 Re: sql query
i did that and i have the answer but the problem is

the sqlquery which displays the Forum name from (tlbforum) and username from (tbluser_profile)is

sqlQry1="select tblforum.*,tbluser_profile.Nick_Name AS owner,Count(tblthread.Thread_Id)
FROM tblforum INNER JOIN tbluser_profile ON tblforum.User_Id = tbluser_profile.User_Id ORDER BY tblforum.Creation_Date DESC"



now the query which gives me the number of Threads in each forum is

sqlQry2="SELECT count(tblthread.Thread_Id) , tblthread.Forum_Id
FROM tblthread INNER JOIN
tblforum ON tblthread.Forum_Id = tblforum.Forum_Id
GROUP BY tblthread.Forum_Id"



now how to club sqlQry1 and sqlQry2 into one query so that my Datagrid displays

Thread name,thread initiated by,last post in the thread by.
syedwna at 2007-11-11 23:12:46 >