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

  • Home
  • SEARCH
  • 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 6183655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:24:12+00:00 2026-05-24T01:24:12+00:00

my foundation on SQL is pretty weak so I hope you could bear with

  • 0

my foundation on SQL is pretty weak so I hope you could bear with me. I have three tables: contents, categories, and categorization. The setup was chosen since some content will belong to one or more categories.

I want to fetch contents and its corresponding categories.

This is an overly-simplified version of the current script, without error-checking routines:

$q = "SELECT * FROM contents WHERE contents.foo = 'bar'"
$resource = mysql_query($q);
$categoryFilter = array();

$q2 = "SELECT * FROM categorization WHERE ";
while($content = mysql_fetch_assoc($resource))
{
    $categoryFilter[] = "content_id='" . $content["id"] . "'";
}

if(count($categoryFilter))
{
    $q2 .= implode(" OR ", $categoryFilter);
    mysql_query($q2);
}

That’s the gist of it. I hope you get what I am trying to do. I don’t know if I can actually use JOINS the content_id may be present in multiple rows in categorization. So what I did was to simply append multiple OR‘s, trying to fetch items one by one. I really would not like to use multiple queries in this scenario. I hope anyone could suggest an approach

Thanks for your time

  • 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-05-24T01:24:13+00:00Added an answer on May 24, 2026 at 1:24 am

    One query should be enough to fetch data from all three tables:

    SELECT categories.category_id #, other fields
    FROM contents
    INNER JOIN categorization ON contents.content_id = categorization.content_id
    INNER JOIN categories ON categorization.category_id = categories.category_id
    WHERE contents.content_id = 1 # AND other filters
    

    Tweak the columns in the SELECT clause and/or conditions in WHERE clause according to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I setup Team Foundation Server in such a manner that every uer have
I have two great tables that I would like to use as foundation for
Environment: Workflow Foundation 4, SQL persistence store. Requirement: I have a bookmark which has
My setup is Team Foundation Server 2010. We have some shared Work Item Queries.
In Team Foundation Server is there a way to have work items in one
Environment: Team Foundation Server 2005 Visual Studio 2008 I have a reasonably large project
My team foundation is setup to use port 8080, when I am creating a
I have two workflow foundation (.NET 3.5 SP 1) application which compiles fine. It
I have a little foundation tool test (Objective-C) that I am playing with and
I don't have the (expensive) SQL standard at hand; what are updatable queries in

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.