Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 What's wrong with my MINUS syntax?

Author  Topic 

Piece_Of_Meat
Starting Member

1 Post

Posted - 2014-02-07 : 12:14:05
Im Trying to run SQL Syntax on access. This is my database:
http://postimg.org/image/jvjfy95zj/
I want to get all the customers that have all the action channels but
it gives me an error message.
This is my code:
SELECT C1.customer_id FROM Customers C1 WHERE not exists
(SELECT channel_id FROM Channels Where category=
(SELECT category_id FROM Channel_Categories WHERE category_name="Action"))
MINUS
(SELECT channel_id FROM Channels, Packages_Channels, Packages, Packages_customers, Customers.C2 WHERE
Channels.channel_id= Packages_Channels.channel_id AND
Packages_Channels.package_id= Packages. package_id AND
Packages.package_id=Packages_customers.package_number AND Packages_customers.customer_id= C2.customer_id AND
C2.customer_id=C1. customer_id));


So i took only part of the code and tried to get all the action channels that customer 1 don't have:

SELECT channel_id FROM Channels Where category= 
(SELECT category_id FROM Channel_Categories WHERE category_name="Action")
MINUS
SELECT channel_id
FROM Packages_Channels
WHERE Package_id IN
(SELECT package_id FROM Packages WHERE package_id IN
(SELECT package_number FROM Packages_customers WHERE customer_id=1));


And getting error message.
The code before the MINUS works alone and the code after the MINUS works alone but when i add all together with the minuts it gives me a syntax error.
Why is that?[url][/url][url][/url][url][/url][url][/url]

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-07 : 12:41:19
I don't have any Access experience, but is MINUS supported in Access? I believe MINUS is an Oracle thing. In SQL Server, which is the forum you've posted in, you could use EXCEPT syntax. Does Access support EXCEPT?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-10 : 05:23:17
quote:
Originally posted by tkizer

I don't have any Access experience, but is MINUS supported in Access? I believe MINUS is an Oracle thing. In SQL Server, which is the forum you've posted in, you could use EXCEPT syntax. Does Access support EXCEPT?

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/


As far as I know it doesnt
I think you need to use query with LEFT JOIN syntax and check for NULL

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -