Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2013
    Posts
    11

    Question Unanswered: Hi i'm beginer in sql and i have exams to do the folowing

    I have tow tables
    1- threads(threadid, threadname,forumid)
    2- forums(forumid,forum,description)

    I need to create view show all forums exist with count of threads in every one like:
    "forum name" --- "total threads"

    please as soon as possible

    thanks you any way

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    do you know SQL?
    I ask since you posted no SQL; not even CREATE TABLE statements.
    What should be done if no threads exist for any forum?
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  4. #4
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Something like this might do the job; outer join is here for situations Anacedent mentioned (no threads in some forums).
    Code:
    create or replace view v_forum as
    select 
      f.forum, 
      count(t.forumid) total_threads
    from threads t,
         forums f
    where f.forumid = t.forumid (+)
    group by f.forum

  5. #5
    Join Date
    Nov 2003
    Posts
    2,934
    Provided Answers: 12
    Littlefoot, please use the (modern) ANSI 92 outer join syntax instead of Oracle's (+) operator - especially when giving examples to a student (using the JOIN syntax is recommended by Oracle anyway)
    I will not read nor answer questions where the SQL code is messy and not formatted properly using [code] tags: http://www.dbforums.com/misc.php?do=bbcode#code

    Tips for good questions:

    http://tkyte.blogspot.de/2005/06/how...questions.html
    http://wiki.postgresql.org/wiki/SlowQueryQuestions
    http://catb.org/esr/faqs/smart-questions.html

  6. #6
    Join Date
    Mar 2013
    Posts
    11

    Thanks so much

    i have did it

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •