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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:35:03+00:00 2026-06-03T05:35:03+00:00

I have concluded that my first quick fix of storing an array of ids

  • 0

I have concluded that my first quick fix of storing an array of ids in a singular database field (1,5,48) is probably not best but if I break them out into a joining table of ‘parent item id’ (singular) and then sub related item id (multiple) which links to a separate table it would be better.

But now I am unsure what mysql query to use to get matches.

So a search form is submitted where “related_item” array is “1,5,8” and one of my “parent_items” has related item matches of “1” and “8” in the joining table….

So what mysql query would return these matches?

UPDATE:

  • I have one table ‘companies’ maybe HSBC and TOPSHOP as example records.
  • There is a separate table of ‘industries’ maybe ‘banking’ and ‘retail’
  • There is a joining table which is company_id and industry_id which pairs them both together

So if someone submits a search form for where industry = ‘banking’ or ‘retail’ how would I return the company records for ‘topshop’ and ‘hsbc’

  • 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-03T05:35:04+00:00Added an answer on June 3, 2026 at 5:35 am

    Something like this… its unclear to me form you description if you are “searching” children or parents. I think you mean to search children so:

    -- SEARCH CHILDREN --
    SELECT p.*, c.* FROM child_table c
    LEFT JOIN linking_table l ON (p.id = l.child_table_id)
    LEFT JOIN parent_table p ON (l.parent_item_id = p.id)
    WHERE c.id IN (1,5,4,8)
    -- OPTIONAL AND CLAUSE for p.id = ? --
    

    If you mean to search parents then you can just rework the order, although you could use the exact same query with the exception that your WHERE IN clause would be on p.id instead of c.id.

    Be aware though that this will get you 1 row per match for the children so you will have the same parent multiple times. If you dont need the actual child data then you could use DISTINCT to only return one instance.

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

Sidebar

Related Questions

I have a great idea for a 3D network game, and I've concluded that
After many cases of trial and error, I have concluded that the only solution
I'm not the first to have these issues, and will list some reference posts
Okay this is one of those situations where I have concluded that I am
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have some code that allows users to upload file attachments into a varbinary(max)
I have an attribue attempts in database of integer type (initial value is 0
First of all, I'm not too comfortable with DLL's. I've done them before, but
I have written a very simple socket server. It listens in post 63254. First
I have a class in C++/CLI that I'd like to give a property. I

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.