 <p>Give this a try:</p> <pre><code>select max(s.sNum) result from s2tmap st join s on st.sId = s.sId where st.tId = '000' and not exists ( select * from temp where temp.newId = st.sId) </code></pre> <p>Here is the <a href="http://sqlfiddle.com/#!5/26124/9" rel="nofollow">fiddle</a> to play with.</p> <p>Another option, probably less efficient would be:</p> <pre><code>select max(s.sNum) result from s2tmap st join s on st.sId = s.sId where st.tId = '000' and st.sId not in ( select newId from temp) </code></pre>