Hello
I have a table of equipment listed by what kind of equipment and what sample of that equipment it is. For example, if I have two axes, which have the equipment number 1, the first has the sample number 1, and the other 2.
I also have a table of people lending that equipment. If person 112054 borrows axe 1 1, it is registered with a date of lending. It is also registered with a date of return, if it's returned.
I want to make two queries: One that lists all samples that are not lentout, and one that lists all samples that are lent out.
I managed to make a query for the former of the queries: the one that lists all samples that I have not lent out. My thought for making the other one, the one that lists everything that's lent out, was to do a subquery.
First query, this one works (qryUtstyrInne, samples that are not lent out):
Code:
SELECT E.Utstyrsnr, E.Eksemplarnr
FROM Eksemplar AS E
WHERE NOT EXISTS (
SELECT *
FROM Utlån AS U
WHERE U.Utstyrsnr = E.Utstyrsnr
AND U.Eksemplarnr = E.Eksemplarnr
)
OR NOT EXISTS (
SELECT *
FROM Utlån AS U
WHERE U.[Levert inn] IS NULL
)
So my next thought was this (qryUtstyrUte, empty):
Code:
SELECT E.Utstyrsnr, E.Eksemplarnr
FROM Eksemplar AS E
WHERE NOT EXISTS (
SELECT *
FROM qryUtstyrInne AS Q
WHERE E.Utstyrsnr = Q.Utstyrsnr
AND E.Eksemplarnr = Q.Eksemplarnr
)
But this one does not return anything at all, even when in the table Eksemplar, there are items that are not let out, and one that is let out.
Is there anyting obvious that I'm doing wrong here? I have saved the query qryUtstyrInne.
EDIT:
Here come the tables:
Eksemplar
Utstyrsnr |
Eksemplarnr |
1 |
1 |
2 |
1 |
2 |
2 |
Utlån
Utlånsnr |
Studentnr |
Utstyrsnr |
Eksemplarnr |
Utlånsdato |
Levert inn |
3 |
112054 |
1 |
1 |
04.07.2013 |
|
Utstyr
Utstyrsnr |
Betegnelse |
1 |
Nøkkel, lager, Elverhøy |
2 |
Lavvo |
qryUtstyrInne
Utstyrsnr |
Eksemplarnr |
2 |
1 |
2 |
2 |
qryUtstyrUte is empty.