Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get data with multiple references to single table
    primarykey
    data
    text
    <p>I have <code>Image</code> table with 3 columns: <code>Id</code>, <code>Name</code>, and <code>RefId</code> - It will contain <code>Id</code> from other table (with this example is <code>Category</code> table and <code>Product</code> table). <code>Category</code> table with 3 columns: <code>Id</code>, <code>Name</code> and <code>ProductId</code>. <code>Product</code> table includes 3 columns: <code>Id</code>, <code>Name</code>. This is Product's data:</p> <pre><code>Id Name 659543D6-1A0D-4151-B94C-F44CCDA752B5 Product1 5C1A5A2F-4579-41D2-8FAE-93EF71451285 Product2 2C35A651-1681-4E5E-9F0C-315169BDFA1D Product3 </code></pre> <p>And <code>Category</code>'s data:</p> <pre><code>Id Name ProductId F3FFF612-1D6D-4447-B472-2486C4893CDD Category1 659543D6-1A0D-4151-B94C-F44CCDA752B5 4A2FF39D-13E0-4365-8DEA-7FAD6D6DF405 Category2 659543D6-1A0D-4151-B94C-F44CCDA752B5 599AEA59-8A85-409C-9026-7E4313AF523D Category3 659543D6-1A0D-4151-B94C-F44CCDA752B5 </code></pre> <p>Image's data: </p> <pre><code>Id Name RefId BDD396A2-37A7-4B20-B8C5-8EF2CD58D4C0 Image1 659543D6-1A0D-4151-B94C-F44CCDA752B5 7CDA01FF-B98A-4CDC-A92B-0E31A9CDCD20 Image2 F3FFF612-1D6D-4447-B472-2486C4893CDD </code></pre> <p>Please see this data for the example: <em>Image1</em> is the image of the product and <em>Image2</em> is the image of the category. And my query:</p> <pre><code> SELECT Category.Id, Category.Name, Product.Name, Image.Name FROM Category INNER JOIN Product ON Category.ProductId = Product.Id INNER JOIN Image ON Category.Id = Image.RefId -- ON Product.Id = Image.RefId </code></pre> <p>With this query only get <em>Image2</em> or <em>Image1</em>. My problem is how to get 2 Image with only one query?</p>
    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.
 

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