SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    requirements changed in join...now...how to do it?

    Hi

    I have 2 tables, faq and faq_categories...i have a join that work, and so far, I was a happy camper.

    But...requirements change, and i have to change the join, but i don't know how to do it

    Here is the current code that works just fine:

    Code:
    SELECT faq.* , faq_categories.categoryname 
                                          FROM faq 
                                          JOIN faq_categories
                                          ON ( faq.catid = faq_categories.catid)
    So far, all faq belongs to one category...but from now on, there will be faq which will not belonng to any category....and that complicate things, at least for me.

    How should I change this code in order to display the faq which does not have catid?

    Here are my tables:

    Code:
    CREATE TABLE IF NOT EXISTS `faq_categories` (
      `catid` int(11) NOT NULL AUTO_INCREMENT,
      `parentid` int(11) DEFAULT NULL,
      `categoryname` varchar(255) NOT NULL,
      `categoryname_en` varchar(255) DEFAULT NULL,
      `description` text,
      `description_en` text,
      `metatags` text,
      `metatags_en` text,
      `sorder` int(11) NOT NULL,
      `visible` tinyint(4) NOT NULL,
      `categoryphoto` varchar(255) DEFAULT '',
      PRIMARY KEY (`catid`),
      KEY `parentid_fk` (`parentid`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=204 ;
    
    
    CREATE TABLE IF NOT EXISTS `faq` (
      `faqid` int(11) NOT NULL AUTO_INCREMENT,
      `catid` int(11) DEFAULT NULL,
      `question` text NOT NULL,
      `question_en` text NOT NULL,
      `answer` text,
      `answer_en` text,
      `metatags` text,
      `metatags_en` text,
      `sorder` tinyint(4) DEFAULT NULL,
      `visible` tinyint(4) DEFAULT NULL,
      PRIMARY KEY (`faqid`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
    Any help will be deeply appreciated.

    Regards,Zoreli

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Solved

    I found it...It only needed a LEFT before the JOIN. Now work like a charm.

    Regards,Zoreli

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    well done

    p.s. the parentheses in your ON clause are superfluous
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Tags for this Thread

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
  •