Results 1 to 4 of 4
  1. #1
    Addy75 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    3

    How to INSERT INTO with more than one SELECT statement.


    Hey everyone, I just wondered if this is possible. My code will say it all

    Code:
    INSERT INTO DVD(DVD_ID,Title,Description,Rating_ID)
    SELECT '111','Rambo','Stallone', 
    Rating_ID FROM Rating WHERE Rating ='R'
    The code above works but I need to get data from two other tables and the following code does not work:

    Code:
    INSERT INTO DVD(DVD_ID,Title,Description,Rating_ID,Format_ID,Category_ID)
    SELECT '111','Rambo','Stallone', 
    Rating_ID FROM Rating WHERE Rating ='R',
    Format_ID FROM Format WHERE Format ='DVD',
    Category_ID FROM Category WHERE Category ='Action_Adventure'
    I get an error of: "Number of query values and destination fields are not the same."

    Any alternative for this or do I have to create two INSERT statements? Any help will be appreciated. Thank you

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    Dubai
    Posts
    614
    Create > query , Select your table and change the query to APPEND query. You will have the correct syntax.

  3. #3
    Addy75 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    3
    Thank you for your response. So it did convert my statement into this when I include just one of my outside tables:
    Code:
    INSERT INTO DVD ( DVD_ID, Title, Description, Rating_ID )
    SELECT '111' AS Expr1, 'Rambo' AS Expr2, 'Stallone' AS Expr3, Rating.Rating_ID
    FROM Rating
    WHERE (((Rating.[Rating])='R'));
    It says I'm about to append 1 row and when I click yes I get this message:
    Attachment 19038

  4. #4
    Addy75 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    3
    They are all varchar(20) so I don't understand the conversion failure.

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

Similar Threads

  1. Replies: 1
    Last Post: 10-29-2014, 10:19 AM
  2. Insert statement fail
    By JeroenMioch in forum Access
    Replies: 3
    Last Post: 04-29-2014, 09:11 AM
  3. INSERT statement
    By GraeagleBill in forum Programming
    Replies: 2
    Last Post: 03-29-2013, 12:53 PM
  4. Insert Into statement
    By TimMoffy in forum Programming
    Replies: 7
    Last Post: 07-13-2012, 07:10 AM
  5. Insert statement
    By crowegreg in forum Programming
    Replies: 2
    Last Post: 08-19-2011, 02:20 PM

Tags for this Thread

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