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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:53:51+00:00 2026-05-24T05:53:51+00:00

Im trying to do something like this (This is MySQL format) SELECT q.question_id, q.question,

  • 0

Im trying to do something like this (This is MySQL format)

SELECT q.question_id, q.question, q.answer
FROM relationship r, questions q
WHERE r.cat_id =1
AND r.question_id = q.question_id
LIMIT 0 , 30

So, I got questions stored in one table, then categories in another table. I have the relationship table set up so that a question can be in multiple categories. So say a question has an id of 5, and its in 3 different categories, the relationship table would look like this

relation_id, question_id, category_id
    1            5            1
    2            5            2
    3            5            3
    4            6            1  

So, say I wanna get all the questions with the cat_id of 1, I should get 2 results. That’s basically what I’m trying to do.

  • 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-24T05:53:52+00:00Added an answer on May 24, 2026 at 5:53 am

    If you want all questions with cat_id of 1, then you want this:

    select q.question, q.answer
    from questions q
    join relationship r on q.question_id = r.question_id
    where r.cat_id = 1
    

    I’ve switch to the ANSI join syntax rather than implied join conditions in the WHERE clause because the explicit version helps to avoid certain types of errors; in particular, ANSI joins help avoid accidental cross products and that’s what your “MySQL format” query has because you neglected to include a join condition for category. That accidental cross product is almost certainly the source of your “returns each item 3 times” problem.

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

Sidebar

Related Questions

I'm trying to do something like this: DELETE FROM table_1 WHERE table_1.id IN (SELECT
I'm trying to do something like this: SELECT t1.*, t2.* FROM (SELECT * FROM
I am trying to use jQuery with MYSQL and I wrote something like this
I'm trying to do something like this: SELECT MAX( ADDDATE(expirationdate, INTERVAL 1 YEAR), ADDDATE(now(),
I am trying to do something like this: SELECT a.date AS EnrollDate, a.id, a.name,
I'm trying to do something like this in My MySQL stored proc: if val
Got question. If i make query to server i use something like this: mysql_query(select
i am trying to select information from my mysql database with this statement after
If I have a MySQL statement like this: $sql=SELECT `name`, DATE(`time`), FROM `students` WHERE
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the

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.