MySQL Forums
Forum List  »  General

`3` querys for the same thing?
Posted by: Xhavick Past
Date: July 13, 2012 04:38PM

Hi everyone, I'm relatively new in sql language, so i have one question i hope somebody can help me.

I'm trying to insert new rows in a table that have index with no primary keys and without unique, then i want to prevent from insert duplicate a DATE that already exists in the primary table.

First thing first:

fec_informacion date
sdo_real_e int
nombre varchar(50)

then

INSERT INTO tb1 (FEC_INFORMACION, SDO_REAL_E, NOMBRE)
SELECT FEC_INFORMACION, SDO_REAL_E, NOMBRE
FROM tb2

# NOW TO PREVENT DUPLICATE ROWS I've tried with 3 different options. It appears to be the same result. I need to confirm that, because i really don't find any difference in my tests. The 3 options los like:

# WHERE fec_informacion NOT IN(SELECT fec_informacion FROM tb1);

# WHERE tb2.FEC_INFORMACION > (select max(fec_informacion) from tb1);

# WHERE NOT EXISTS(SELECT FEC_INFORMACION FROM tb1 where tb1.FEC_INFORMACION = tb2.FEC_INFORMACION);

Anticipated thanks to all for read this.

Options: ReplyQuote


Subject
Written By
Posted
`3` querys for the same thing?
July 13, 2012 04:38PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.