user2283654
user2283654

Reputation: 33

Not getting the syntax of EXCEPT Right

I am sybase adaptive server 12.5.4 and this query does not seem to run

SELECT login,account from tempdb.guest.acct_info_dr3
EXCEPT
SELECT login,account from tempdb.guest.acct_info_dr2

I have checked white spaces etc. But I keep getting this error Incorrect syntax near Except.

Strangey MINUS which is oracle function worked.

Upvotes: 3

Views: 5780

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269603

You can always rephrase this as a left outer join:

select dr3.login, dr3.account
from tempdb.guest.acct_info_dr3 left outer join
     (select distinct login, account
      from tempdb.guest.acct_info_dr2
     ) dr2
     on dr2.login = dr3.login and dr2.account = dr3.account
 where dr2.login is NULL

This will work, unless the columns contain NULL values. If so, that can be fixed with additional logic.

Upvotes: 4

Related Questions