Need to get message count from sql table...

  • hello frnds,

    i have three tables namely,

    account_details Columns: username,password

    personal_details Columns:username,fname,laname,mailid

    question_details Columns:usename,qid,questions,answers

    now i want to get no.of questions from question_details of all users for that i tried a query is

    "select count(question_details.username) as postcount,* from personal_details,question_details where personal_details.username and question_details.username in(select username from account_details)"

    but its not useful for me,it throws some error... can anyone knows solution plz help me..

    thank u...

  • I think this meets your needs:

    [font="Courier New"]SELECT

       COUNT(QD.qid) AS postcount,

       PD.username,

       PD.laname,

       PD.fname,

       PD.mailid

    FROM

       personal_details PD JOIN

       question_details QD ON

           PD.username = QD.username

    WHERE

       EXISTS (SELECT 1 FROM account_details WHERE username = PD.username)

    GROUP BY

       PD.username,

       PD.laname,

       PD.fname,

       PD.mailid[/font]

    You really don't need the Where clause unless you have person_detail rows without a matching username in account_details.

  • hey thanks a lot frnd...Ur query is working fine..

    i have another need also...

    In previous i mentioned three tables

    account_details Columns: username,password

    personal_details Columns:username,fname,laname,mailid

    question_details Columns:usename,qid,questions,answers

    and i asked personal details and message count from those table,

    now i also need blog count from table by using this table,

    blog_details Columns:usename,blogid,blogs,blog_solution

    can u help me...thanks..

  • If you are managing/programming this system you should be able to figure out the solution based on the previous solution I provided. I suggest you get yourself a beginners SQL query book like, Microsoft® SQL Server® 2008 T-SQL Fundamentals.

  • hey frnd dont get mistaken me...

    i need to get message count from question_details,blogs count from blog_detail,personal information from personal_details of all user who are in account_details table.

    account_details Columns: username,password

    personal_details Columns:username,fname,laname,mailid

    question_details Columns:usename,qid,questions,answers

    blog_detail Columns:username,blogid,blogs,blog_solution

    i dont want to get blog count from blog_detail table alone frnd..

  • Please see this article on how to get better results from these forums: http://www.sqlservercentral.com/articles/Best+Practices/61537/

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • sadaiyan,

    People here volunteer their time and skill, and we are happy to try and help, but we expect you to try and do some work. We expect you to make an attempt and post code, not just ask for someone to do your work for you.

    Jack gave you a hint, you can should try to work with that, or ask another question about something you don't understand, but this isn't rent a coder. You have a query you can use to try, so please do so and do not get upset when we ask you to do some work yourself.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply