Jump to content

Confusing SQL query


int3grate

Recommended Posts

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

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

  • 1 month later...
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

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

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

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

Isn't that what I said? :)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...