Reputation: 25
While using minus clause in between two statements giving some error. Can someone help me with this?
Error is Msg 102, Level 15, State 1, Line 101 Incorrect syntax near 'MINUS'.
SELECT a from (SELECT DISTINCT(name) as a FROM hack WHERE name LIKE '%') a
MINUS
SELECT b from (SELECT DISTINCT(name) as b FROM hack WHERE name LIKE '[aeiou]%[aeiou]') b
Upvotes: 0
Views: 4103
Reputation: 104
MINUS is exist in Oracle. By seeing your error message, I hope you are looking in SQL Server.
In SQL Server, EXCEPT is the correct replacement for MINUS.
SELECT DISTINCT name
FROM hack
WHERE name LIKE '%'
EXCEPT
SELECT DISTINCT name
FROM hack
WHERE name LIKE '[aeiou]%[aeiou]'
Upvotes: 2
Reputation: 1269923
You can simplify the logic to:
SELECT DISTINCT name
FROM hac
WHERE name NOT LIKE '[aeiou]%[aeiou]'
A simple comparison should be much more efficient that multiple comparisons along with set operators.
Upvotes: 1