[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to do similar query like Oracle using not exists
Hi,
I try to do an Oralce query in mySQL
insert into geoTable select '011852','HK' from dual where not exists
(select * from geoTable where geoID = '011852')
In Oracle, this query will check the new geoID is not exist before
inserting into the table.
In mySQL, I do
create temporary table tmp1 select '011852' geoID, 'HK' countryName;
create temporary table tmp2 select a.geoID, a.countryName from tmp1 a
left join geoTable b on a.geoID = b.geoID where a.geoID is null;
insert into geoTable select * from tmp2;
Do anyone know mySQL has a similar function like Oracle to check "NOT
EXISTS" or there is a better queries than what I use here.
Thanks
Wai Lee
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <mysql-thread92941@xxxxxxxxxxxxxxx>
To unsubscribe, e-mail <mysql-unsubscribe-treed=ultraviolet.org@xxxxxxxxxxxxxxx>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
This mailing list archive is a service of Copilot Consulting.