Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As @Shiplu pointed out, this is largely a normalization issue. Despite what some people seem to think, multi-value columns are <em>murder</em> to try to get right.</p> <p>Your basic issue is:<br> You have members, who are interested in one or more companies/industries, which belong to one or more industries. You table structure should probably start as: </p> <pre><code>Industry =============== id -- autoincrement name -- varchar Company ============== id -- autoincrement name -- varchar Company_Industry =============== companyId -- fk reference to Company.id industryId -- fk reference to Industry.id Member =============== id -- autoincrement name -- varchar email -- varchar Member_Interest_Industry ========================= memberId -- fk reference to Member.id industryId -- fk reference to Industry.id Member_Interest_Company ======================== memberId -- fk reference to Member.id companyId -- fk reference to Company.id </code></pre> <p>To get all companies a member is interested in (directly, or through an industry), you can then run something like this: </p> <pre><code>SELECT a.name, a.email, c.name FROM Member as a JOIN Member_Interest_Company as b ON b.memberId = a.id JOIN Company as c ON c.id = b.companyId WHERE a.id = :inputParm UNION SELECT a.name, a.email, d.name FROM Member as a JOIN Member_Interest_Industry as b ON b.memberId = a.id JOIN Company_Industry as c ON c.industryId = b.industryId JOIN Company as d ON d.id = c.companyId WHERE a.id = :inputParm </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload