Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:25:01+00:00 2026-06-12T18:25:01+00:00

I have 2 tables, faq and faq_categories…i have a join that work, and so

  • 0

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:

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:

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 ;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:25:04+00:00Added an answer on June 12, 2026 at 6:25 pm

    For those that have no category, we assume you mean faq.catid will be NULL. Your table definitions don't need to change at all. That will only require changing yourINNER JOINto aLEFT JOIN. The FAQs with no category will show aNULLforfaq_categories.categoryname` in the output:

    SELECT 
      faq.* , 
      faq_categories.categoryname 
    FROM
      faq 
      LEFT JOIN faq_categories  ON ( faq.catid = faq_categories.catid)
    

    I would encourage you now to anticipate the time when a FAQ must belong to more than one category, however. To do that, you need to create a joining table which contains a faqid and catid. There can be many rows per faqid:

    CREATE TABLE faq_in_categories (
      faqid INT(11) NOT NULL,
      catid INT(11) NOT NULL,
      PRIMARY KEY (faqid, catid),
      FOREIGN KEY (faqid) REFERENCES faq (faqid),
      FOREIGN KEY (catid) REFERENCES faq_categories (catid)
    );
    

    Under this model, you would remove the faq.catid column because membership in a category is defined in the joining table. This is a many-to-many relationship.

    Queried by:

    SELECT 
      faq.*
      categories.*
    FROM
      faq
      JOIN faq_in_categories ON faq.faqid = faq_in_categories.faqid
      JOIN categories ON faq_in_categories.catid = categories.catid
    WHERE faq.faqid = 'some faqid'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 tables, faq and faq_categories, and I want to join them to
I have a query that works on MySQL but doesn't work on Oracle, and
I have tables like that in Datagridview: Name Money ------------- Hi 100 //here Combobox
I'm creating a self-help FAQ type application and one of the requirements is that
I have tables with listings, categories and one that maps them to each other.
I have tables like Person{id, name, dob} employee{id, company_name, joining_date}. I need to join
I'm designing a database that has a couple of tables; FAQ's, Bulletins, and Attachments.
I've got the following tables: magazine_tags news_tags page_tags content_tags faq_tags They all have exactly
I have tables A and B with identity PKs ida and idb : ex
I have tables like these two test_table date student test 2012-05-31 Alice Math 2012-05-31

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.