Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6845733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:32:13+00:00 2026-05-27T00:32:13+00:00

I am inserting data into a table by selecting from another table which may

  • 0

I am inserting data into a table by selecting from another table which may have duplicates. I thought my query was handling this by checking if the row already exists but I am getting a unique constraint violation.

Here is the query:

INSERT INTO FOLDER_USER (FOLDER_ID, USER_ID) 
    SELECT DECODE(FOLDERID,'F10', '1','F565','2','F11', '3','F81', '4','0'), USERID
    FROM DATA1.FOLDERS F1
    WHERE UPPER(OWNER) = 'ADMIN'
    AND NOT EXISTS 
        (SELECT 1 FROM FOLDER_USER F2  
         WHERE DECODE(FOLDERID,'F10', '1','F565','2','F11', '3','F81', '4','0')= F2.FOLDER_ID 
         AND F1.USERID = F2.USER_ID);
  • Table FOLDER_USER contains 2 columns FOLDER_ID (number), USER_ID
    (varchar) and combined they make up the primary key
  • Table FOLDERS contains 2 columns FOLDERID and USERID (both varchars). The value
    in FOLDERID needs to be decoded into a number depending on its value
    before being inserted into the new table
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:32:14+00:00Added an answer on May 27, 2026 at 12:32 am

    Perhaps the rows you are selecting are not unique within themselves.

    Try:

    INSERT INTO folder_user( folder_id,
                             user_id)
       SELECT UNIQUE 
              DECODE( folderid,  'F10', '1',  'F565', '2',  'F11', '3',  'F81', '4',  '0' ),
              userid
         FROM data1.folders f1
        WHERE UPPER( owner ) = 'ADMIN'
              AND NOT EXISTS
                     (SELECT 1
                        FROM folder_user f2
                       WHERE DECODE( folderid,  'F10', '1',  'F565', '2',  'F11', '3',  'F81', '4',  '0' ) = f2.folder_id
                             AND f1.userid = f2.user_id);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i am having problem inserting data into multiple table from one view. First
I'm having trouble inserting data into a table. I have the following tables: track
This is a pretty simple problem. Inserting data into the table normally works fine,
I'm writing application for downloading CSV file from web and inserting data into table
i have a problem in inserting some data into a table. I have done
I am having problems when inserting data into a sqlite table, I have read
I am inserting data into a table which contains some basic html tags, double
I am inserting data into a table in Sqllite DataBase which are ever increasing
I get the following error when inserting data from mysql into postgres. Do I
The problem is during inserting data from staging table during import routine. The system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.