Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect with multiple clauses
    text
    copied!<p><strong>Schema</strong></p> <p>I have 3 tables with the following columns:</p> <pre><code>tblClients [ClientID, ClientName, Client Contact] tblEvents [EventID, EventName] tblEventBook [EventBookID, EventID, ClientID] </code></pre> <ul> <li><code>tblEventBook EventID</code> matches <code>tblEvents EventID</code></li> <li><code>tblEventBook ClientID</code> matches <code>tblClients ClientID</code></li> </ul> <p>I have two parameters: <code>@useEventID</code> and <code>@useClientID</code></p> <p>I would like to retrieve all rows from <code>tblClient</code> where <code>tblEventBook</code> does not equal <code>useEventID</code> and <code>useClientID</code>.</p> <p>I tried to use the below, but it does not work:</p> <pre><code>SELECT * FROM tblClients WHERE tblEventBook.EventID &lt;&gt; @useEventID AND tblEventBook.ClientID &lt;&gt; @useClientID </code></pre> <p>Sample Data:</p> <p><strong>tblEventBook</strong></p> <pre><code>EventBookID EventID ClientID 1 1 1 2 2 2 3 3 1 4 4 2 </code></pre> <p><strong>tblClients</strong></p> <pre><code>ClientID ClientName ClientContact 1 TestNameA 12345 2 TestNameB 54321 </code></pre> <p><strong>tblEvents</strong></p> <pre><code>EventID EventName 1 TestEventA 2 TestEventB 3 TestEventC 4 TestEventD 5 TestEventE </code></pre> <p>Required results</p> <p>I need to get the below results when I use:</p> <ol> <li><p><code>@useClientID = 1, @useEventID = 1</code></p> <p>It should return <code>ClientID 2</code></p></li> <li><p><code>@useClientID = 2, @useEventID = 1</code></p> <p>It should return <code>ClientID 1 and 2</code></p></li> <li><p><code>@useClientID = 2, @useEventID = 2</code></p> <p>It should return <code>ClientID 1</code></p></li> <li><p><code>@useClientID = 5, @useEventID = 2</code></p> <p>It should return <code>ClientID 1 and 2</code></p></li> </ol>
 

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