int3grate Posted September 23, 2006 Share Posted September 23, 2006 I'm trying to construct this query using sql in microsoft access, and I'm having a little trouble finding a way to do it.I have an items-sold table that looks similar to this: item_name department-------------------------------------------------Geo positioning system NavigationMap measure NavigationGeo positioning system BooksSextant BooksPocket knife-Nile BooksPocket knife-Nile Clothes I need build a query that list departments that have not sold a Geo position system. Any ideas? Link to comment Share on other sites More sharing options...
redsun Posted September 23, 2006 Share Posted September 23, 2006 Just try this: SELECT department FROM yourtablename WHERE item_name NOT LIKE 'Geo positioning system' Redsun Link to comment Share on other sites More sharing options...
int3grate Posted September 23, 2006 Author Share Posted September 23, 2006 Just try this:SELECT department FROM yourtablename WHERE item_name NOT LIKE 'Geo positioning system' Redsun That doesn't work. That query will return departments that have sold Geo Positioning systems.... Link to comment Share on other sites More sharing options...
redsun Posted September 23, 2006 Share Posted September 23, 2006 That doesn't work. That query will return departments that have sold Geo Positioning systems....Did you tryed the query? There is "NOT LIKE" which will return the department names NOT selling "Geo positioning system". Link to comment Share on other sites More sharing options...
jesh Posted September 25, 2006 Share Posted September 25, 2006 Can Access handle multiple SELECTs like SQL Server? If so, this might work for you: SELECT department FROM yourtablename WHERE department NOT IN (SELECT department FROM yourtablename WHERE item_name LIKE 'Geo positioning system') Link to comment Share on other sites More sharing options...
lordfa9 Posted November 3, 2006 Share Posted November 3, 2006 SELECT department FROM yourtablename WHERE item_name NOT LIKE 'Geo positioning system'I think you missed out on soemthing the phrase you want to use for the LIKE statement should have a * at the start and endTry this SELECT department FROM yourtablename WHERE item_name NOT LIKE "*Geo positioning system*" Link to comment Share on other sites More sharing options...
justsomeguy Posted November 7, 2006 Share Posted November 7, 2006 SELECT department FROM yourtablename WHERE item_name NOT LIKE 'Geo positioning system'That query does not work because in this case: Geo positioning system NavigationMap measure Navigation It will select the Navigation department because it has an entry where it does not include the GPS, even though the GPS is on another row. The query just tells it to select all departments where there is a row without the GPS in it. If Access supports subqueries, then jesh's answer will work. Link to comment Share on other sites More sharing options...
aalbetski Posted November 7, 2006 Share Posted November 7, 2006 This works in SQL Server. Not sure about Access select department from items_sold where department not in (select department from items_sold where item_name = 'Geo positioning system') It uses a sub query to first determine all the departments that have sold a Geo positioning system and then the outer query excludes them Link to comment Share on other sites More sharing options...
jesh Posted November 7, 2006 Share Posted November 7, 2006 This works in SQL Server. Not sure about Accessselect department from items_sold where department not in (select department from items_sold where item_name = 'Geo positioning system') It uses a sub query to first determine all the departments that have sold a Geo positioning system and then the outer query excludes them Isn't that what I said? Link to comment Share on other sites More sharing options...
aalbetski Posted November 8, 2006 Share Posted November 8, 2006 Yes, and I had edited it to that effect, somehow it came back, sorry Link to comment Share on other sites More sharing options...
jesh Posted November 8, 2006 Share Posted November 8, 2006 Yes, and I had edited it to that effect, somehow it came back, sorryHeh, no worries. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now