Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Query with subqueries

Status
Not open for further replies.

ailyn

Programmer
Sep 15, 2005
108
BE
I have a query with a subquery that works perfectly, but I need to filter it even more. this is my actual query:

SELECT Location.Location, Location.LocationId
FROM Location
WHERE Location.LocationId NOT IN
(SELECT Products.LocationId
FROM Products)
ORDER BY Location.Location;

I'd like to add another subquery but they don't seem to work. Probably this is not possible?

My other subquery would be:

(SELECT Products.LocationId, Products.[uit]
FROM Products
WHERE (((Products.[uit])=True)))

I intend to show only the 'locations' that have products.uit marked (those are products that are gone and freed their location) or that have no products at all ==> All free locations.

Any ideas? I've been working on it some time, but I still can't get it. any help would be highly appreaciated.
 
Don't think you need another sub query ... just add the where clause to the existing one.
Code:
SELECT Location.Location, Location.LocationId
FROM Location
WHERE Location.LocationId NOT IN
(SELECT Products.LocationId
FROM Products
[COLOR=blue]WHERE Products.[uit]=True[/color] )
ORDER BY Location.Location;
 
Well, thanks Golom but that doesn't work either.
My previous query (the first one that worked) showed all the values in location that were absolutely free. With the filter on products (second query I included in my first post) I intended to show all values that were free (never had a product Id and the values of location that had products but now were free = when the product gets sold 'Products.[uit] = True' the location is free again.

The query you gave me showed all the values that where free and all the values that were occupied at the moment with non-sold products. It only hid the values that had been freed.
Do I explain myself or I'm making it too complicated?

Now I tried Products.[uit] = False and it works. What doesn't make any sense to me because when they are marked True is when they have been marked as sold. But it works!
THANKS!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top