Note that there are some explanatory texts on larger screens.

plurals
  1. POFilter Table Before Applying Left Join
    primarykey
    data
    text
    <p>I have 2 tables, I want to filter the 1 table <strong>before</strong> the 2 tables are joined together.</p> <p>Customer Table:</p> <pre><code> ╔══════════╦═══════╗ ║ Customer ║ State ║ ╠══════════╬═══════╣ ║ A ║ S ║ ║ B ║ V ║ ║ C ║ L ║ ╚══════════╩═══════╝ </code></pre> <p>Entry Table:</p> <pre><code> ╔══════════╦═══════╦══════════╗ ║ Customer ║ Entry ║ Category ║ ╠══════════╬═══════╬══════════╣ ║ A ║ 5575 ║ D ║ ║ A ║ 6532 ║ C ║ ║ A ║ 3215 ║ D ║ ║ A ║ 5645 ║ M ║ ║ B ║ 3331 ║ A ║ ║ B ║ 4445 ║ D ║ ╚══════════╩═══════╩══════════╝ </code></pre> <p>OK I want to Left Join so I get all records from the Customer table regardless of whether there are related records in the Entry table. However I want to filter on category D in the entry table <strong>before the join</strong>.</p> <p>Desired Results:</p> <pre><code> ╔══════════╦═══════╦═══════╗ ║ Customer ║ State ║ Entry ║ ╠══════════╬═══════╬═══════╣ ║ A ║ S ║ 5575 ║ ║ A ║ S ║ 3215 ║ ║ B ║ A ║ 4445 ║ ║ C ║ L ║ NULL ║ ╚══════════╩═══════╩═══════╝ </code></pre> <p>If I was to do the following query:</p> <pre><code> SELECT Customer.Customer, Customer.State, Entry.Entry FROM Customer LEFT JOIN Entry ON Customer.Customer=Entry.Customer WHERE Entry.Category='D' </code></pre> <p>This would filter out the last record.</p> <p>So I want all rows from the left table, and join it to the entry table filtered on category D.</p> <p>Thanks to any help in advance!!</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.
    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