Results 1 to 2 of 2
  1. #1
    glennib is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    3

    Subquery Troubles

    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.
    Last edited by glennib; 07-11-2013 at 12:22 PM. Reason: Added tables.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Have you checked out the Lending Library template database? http://office.microsoft.com/en-us/te...010206883.aspx

    I expect it has an example you could follow or could maybe even adapt the db to your situation.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Subreport Keep Together troubles
    By chris.williams in forum Reports
    Replies: 1
    Last Post: 09-07-2012, 12:29 PM
  2. Query troubles.
    By SteveSummers in forum Access
    Replies: 1
    Last Post: 10-26-2011, 07:48 PM
  3. Running Sum Troubles
    By royalrochelle in forum Reports
    Replies: 2
    Last Post: 09-10-2011, 05:13 AM
  4. troubles with validation rules
    By focosi in forum Access
    Replies: 4
    Last Post: 08-02-2011, 10:46 AM
  5. Query troubles
    By dmullins in forum Reports
    Replies: 0
    Last Post: 10-20-2009, 02:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums