Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the correct SQL query for this?
    primarykey
    data
    text
    <p>I have a table that stores all the user activities. I call it the "sessions" table with fields:</p> <pre><code>+--------------------------------------------------+ | id | content_type | content_id | action | +--------------------------------------------------+ </code></pre> <p>content_type can be 1=videos, 2=slideshows, 3=forms, 4=surveys, 5=websites, 6=interactives</p> <p>content_id is the ID of the actual content. For example I have the "websites" table</p> <pre><code>+---------------------------------------------+ | id | name | url | +------------------+--------------------------+ | 3 | Google | http://www.google.com/ | +------------------+--------------------------+ </code></pre> <p>On the app, the user visited the google.com website. What will be stored on the "sessions" table is:</p> <pre><code>+----------------------------------------------------------+ | content_type | content_id | action | +----------------------------------------------------------+ | 5 | 3 | Visited Google Website | +----------------------------------------------------------+ </code></pre> <p>These contents of the "websites" (or forms, videos, etc.) table can be attached or tagged to a number of product groups.</p> <p>I do this by storing it to a table named "attached_product_groups"</p> <p>on that table, I have the fields: </p> <pre><code>+----------------------------------------------------+ | content_type | content_id | product_group_id | +----------------------------------------------------+ </code></pre> <p>For example I have to attach 3 product groups to the google.com website, from the "product_groups" table:</p> <pre><code>+----------------------------+ | id | name | +----------------------------+ | 3 | Mobile | +----------------------------+ | 8 | Social Networking | +----------------------------+ | 9 | Adsense | +----------------------------+ </code></pre> <p>"attached_product_groups" table will store:</p> <pre><code>+----------------------------------------------------+ | content_type | content_id | product_group_id | +----------------------------------------------------+ | 5 | 3 | 3 | +----------------------------------------------------+ | 5 | 3 | 8 | +----------------------------------------------------+ | 5 | 3 | 9 | +----------------------------------------------------+ </code></pre> <p>Now my question is, how do I select all the "session" logs of a cetain product groups?</p> <p>Given that on my app, I have a dropdown of the product groups. </p> <p>Thanks a lot for helping a beginner like me. :)</p>
    singulars
    1. This table or related slice is empty.
    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. 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