Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This should help you test your query. Your question wasn't specific enough, so, this is the best I can do :)</p> <pre><code> DECLARE @client TABLE ( clientid int, company VARCHAR(50) ) DECLARE @supportstatus TABLE ( clientid int, [status] VARCHAR(50), agreement INT ) INSERT INTO @client ([clientid],[company]) VALUES ( 0,'acme' ) INSERT INTO @client ([clientid],[company]) VALUES ( 1,'byron' ) INSERT INTO @client ([clientid],[company]) VALUES ( 2,'cathode' ) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'disabled',0) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'disabled',1) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'somethingelse',0) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 0, 'somethingelse',1) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'disabled',0) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'disabled',1) --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'somethingelse',0) --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 1, 'somethingelse',1) --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'disabled',0) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'disabled',1) --INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'somethingelse',0) INSERT INTO @supportstatus ([clientid],[status], agreement) VALUES ( 2, 'somethingelse',1) -- all companies who have su.agreement = 0 and su.status &lt;&gt; 'disabled' SELECT cl.company FROM @client cl JOIN @supportstatus su ON cl.clientid = su.clientid WHERE su.agreement = 0 AND su.status &lt;&gt; 'disabled' Order By cl.company </code></pre>
 

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