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 8266057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:01:15+00:00 2026-06-08T05:01:15+00:00

I haven’t worked much with databases before but I understand a bit of the

  • 0

I haven’t worked much with databases before but I understand a bit of the basics. Right now, I’ve got two tables, we’ll call Table 1 and Table 2. I’m trying to create a trigger so that when I insert data into Table 1, it fires the trigger to get all distinct values for col1 in Table 1, which I want to use to insert into Table 2. As more data gets added into Table 1, duplicates will no doubt occur. If a duplicate occurs, I don’t want the duplicate inserted into Table 2. So, I thought that I might use a Union to pull the unique values and insert them into Table 2, but after the Union I’m not entirely sure what to do. Am I crazy for thinking this way and there’s a way to do this better?

DELIMITER // 
CREATE TRIGGER testdb 
AFTER INSERT ON testdb.table1
FOR EACH ROW
BEGIN    
    SELECT col1 FROM table1
    UNION
    SELECT col1 FROM table2
    (I imagine the insert statement would go here)
END //
DELIMITER ;

In short, data goes into Table 1, trigger launches on insert to get unique values from Table 1 Col 1 and Table 2 Col 1 in the attempt to get all unique values, and then I want to insert the unique values into Table 2 Col 1, but some of those unique values may already exist.

  • 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-06-08T05:01:17+00:00Added an answer on June 8, 2026 at 5:01 am

    Assuming that table2 is defined as

    CREATE TABLE table2 (col1 ..., PRIMARY KEY(col1));
    

    You could do this:

    DELIMITER // 
    CREATE TRIGGER testdb 
    AFTER INSERT ON testdb.table1
    FOR EACH ROW
    BEGIN    
        INSERT IGNORE INTO table2 SET col1 = NEW.col1;
    END //
    DELIMITER ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I haven't used the STL much before, but I started to on this huffman
I haven't found any documentation on this or seen this done before, but is
I haven't worked with SQL Reporting much, however I have been trying to get
Haven't been coding in a bit, but took on a project for a friend.
I haven't yet worked out a specific case. But I am about to embark
Haven't seen anything about it here but it seems to solve one of the
I haven't actually built an app yet, but I'm confused by documentation on bind-attr.
I haven't designed a website for about 3 years now, so I am quite
I haven't done a lot of work with multi-level, pure CSS drop-down menus before,
this is what i have right now Drawing an RSS feed into the php,

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.