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 6357531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:10:59+00:00 2026-05-24T23:10:59+00:00

This has been driving me mad. I have three tables: items ID name type

  • 0

This has been driving me mad.

I have three tables:

items
  ID
  name
  type

cats
  ID
  name

items_to_cats
  FK_ITEM_ID
  FK_CAT_ID

This is a simple many-to-many relationship. I have items and categories. Each item can be linked to one or more categories. This is done via a simple joining table where each row maintains a relationship between one item and one category using foreign key constraints.

You will notice that my “items” table has a field called “type”. This is an indexed column that defines the type of content stored there. Example values here are “report”, “interview”, “opinion”, etc.

Here’s the question. I want to retrieve a list of categories that have at least one item of type “report”.

Ideally I want to get the result in a single query using joins. Help!

  • 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-24T23:11:00+00:00Added an answer on May 24, 2026 at 11:11 pm
    select distinct cats.id, cats.name
    from cats
    join items_to_cats on items_to_cats.fk_cat_id=cats.id
    join items on items.id=items_to_cats.fk_item_id
    where items.type='report'
    

    Just as a point of database design, if you have a small set of legal values for items.type, i.e. “report”, “interview”, “opinion”, maybe a couple more, then you really should create a separate table for that with, say, an id and a name, then just put the type id in the items table. That way you don’t get into trouble because somewhere it’s mis-spelled “raport”, or even more likely, someone puts “reports” instead of “report”.

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

Sidebar

Related Questions

This problem has been driving me mad. Here's the general gist: I have two
This has been driving me mad for weeks.I have a variable data that I
This has been driving me crazy for the past few minutes I have a
This has been driving me mad someone help coz i don't seem to see
This has been driving me crazy for the past couple of hours. I have
This has been driving me crazy for 2 days. I have been trying to
This has been driving me nuts for a week now. I have a class
This has been driving me nuts all day. I have a weird bug that
This has been driving me mad for the past hour and a half. I
This has been driving me absolutely nuts. I have a substitute function like this:

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.