Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suppose you want two things:</p> <p>1) A list of all items</p> <p>2) A list of all items in boxes</p> <p>You can do this in a couple of ways (I'm guessing the structure of your tables here - I'm guessing ItemBox is the link table)</p> <p>a) Select all of the items, then select a list of all of the items in boxes:</p> <pre><code>SELECT I.ItemID, I.Title, B.BoxId, B.Title FROM Item I INNER JOIN ItemBox IB ON (I.ItemID = IB.ItemID) INNER JOIN Box B ON (IB.BoxID = B.BoxID) ORDER BY B.Title, I.Title </code></pre> <p>Should give you all of the items and their boxes.</p> <p>You can then display a list of all items in a form, and a list of box ids (just simple selects from each table).</p> <p>If you cache the results from the above query (in say a dictionary, BoxItem dictionary) then you can look up the item quite simply based on the selected Box.</p> <p>b) you can run the query each time a box is selected:</p> <pre><code>SELECT I.ItemID, I.Title, B.BoxId, B.Title FROM Item I INNER JOIN ItemBox IB ON (I.ItemID = IB.ItemID) INNER JOIN Box B ON (IB.BoxID = B.BoxID) WHERE B.Id = @selected_boxid ORDER BY B.Title, I.Title </code></pre> <p>And update accordingly.</p> <p>Do you need examples for running the query, binding to various controls etc?</p> <p>Here's a version that should do what you want based on your comment:</p> <pre><code>SELECT I.ItemID, I.Title, CASE WHEN IB.ItemID IS NULL THEN 0 ELSE 1 END AS ItemIsInBox FROM Item I LEFT OUTER JOIN ItemBox IB ON (I.ItemID = IB.ItemID); </code></pre>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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