Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    nightangel73 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    45
    Quote Originally Posted by nightangel73 View Post
    This is the query Stockmovements

    SELECT "Acquisition" AS MovementType, LotNumber, Quantity
    FROM StockAcquisitions

    UNION
    SELECT "Withdrawal" , LotNumber, Quantity*-1
    FROM StockWithdrawals

    UNION SELECT "Stocktake", LotNumber, Quantity
    FROM StockTakes;


    What I want is this same query but with the user name added. But the users are in the table Users

    So if I just simply build a new query using this union query Stock Movements (that works well) and the Users table I get duplicate records.

    SELECT Users.UserID, Users.Name, qryStockMovements.MovementType, qryStockMovements.LotNumber, qryStockMovements.Quantity



    FROM qryStockMovements, ((Users INNER JOIN StockAcquisitions ON Users.UserID = StockAcquisitions.UserID) INNER JOIN StockTakes ON Users.UserID = StockTakes.UserID) INNER JOIN StockWithdrawals ON Users.UserID = StockWithdrawals.UserID;

  2. #17
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Using "SELECT DISTINCT" will remove the duplicate from individual select.

    You have to test and find out if that will give you the result that you are looking for.

  3. #18
    nightangel73 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    45
    This is my closest query so far, now if only you guys can help me with this join statement that I need. Everything I try it's a syntax error message of some sort.


    SELECT "Acquisition" AS MovementType, LotNumber, Quantity, userID, userID.name
    FROM StockAcquisitions

    UNION
    SELECT "Withdrawal" , LotNumber, Quantity*-1, UserID, userID.name
    FROM StockWithdrawals

    UNION SELECT "Stocktake", LotNumber, Quantity, UserID, userID.name
    FROM StockTakes;

  4. #19
    nightangel73 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2014
    Posts
    45
    I got it!!! Here is the query I needed.

    SELECT qryStockMovementsUnion.MovementType, qryStockMovementsUnion.LotNumber, qryStockMovementsUnion.Quantity, qryStockMovementsUnion.userID, Users.Name
    FROM Users RIGHT JOIN qryStockMovementsUnion ON Users.UserID = qryStockMovementsUnion.userID;


    I built another query in design view and created an outer join (#3) between the userID from the qryStockMovement and the UserID from the Users table. Then I dragged the fields I wanted and voila! Can't believe it was so simple.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Format Conatenated fields in Select Statement
    By KWarzala in forum Programming
    Replies: 8
    Last Post: 04-24-2014, 12:36 PM
  2. Select all query fields for main form?
    By tagteam in forum Access
    Replies: 13
    Last Post: 09-15-2013, 04:35 PM
  3. Aggregating fields in Select Query
    By becka11 in forum Queries
    Replies: 3
    Last Post: 05-03-2013, 09:55 AM
  4. Replies: 1
    Last Post: 02-22-2013, 12:46 PM
  5. Replies: 7
    Last Post: 12-30-2012, 03:59 AM

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