SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Finland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Combining two tables

    Hi

    I'm not used to set join queries so i'd like to ask help for this case.

    I have two tables with fields:

    forums:
    forum_id
    forum_priviledge

    topics:
    topic_id
    topic_title
    topic_created
    topic_forum_id

    now i'd like to get 5 newist topics from all forums, where priviledge is 0!

    something like

    SELECT topics.topic_id, topics.topic_title
    FROM topics
    WHERE forums.forum_id=topics.topic_forum_id AND forums.forum_priviledge=0
    ORDER BY topics.topic_created
    ORDER ASC
    LIMIT 5

    But i think i need to join this to get it work or how does it work?

    Regards,
    Marko

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Let me see if I have understood you correctly. Do you want to obtain the five newest topics in all forums (five from the first forum, five from the second forum etc.), or just the five newest topics (regardless of which forum they were posted in) ?

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Finland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just the five newest topics regardless of which forum they were posted in. Sorry for unexact problem description.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,021
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    Code:
    select topic_id
         , topic_title
         , topic_created
         , topic_forum_id
      from topics
    inner
      join forums
        on topic_forum_id
         = forum_id  
     where forum_priviledge = 0     
    order
        by topic_created desc
    limit 5
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Finland
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank You!


Bookmarks

Posting Permissions

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