Mysql: insert if record not exist (in case no unique key)

here is the sql syntax used to insert record when not exist :-

INSERT INTO pengguna(nokp,nama,idlevel,statusdata) SELECT * FROM ( SELECT ‘888888’,’namasaya,’1000′,’1′ ) AS tmp WHERE NOT EXISTS ( SELECT nokp FROM pengguna WHERE nokp=’999′) LIMIT 1

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s