Results 1 to 1 of 1
May 3, 2009, 07:07 #1
- Join Date
- Feb 2005
- was rainy Oregon now sunny Florida
- 2 Post(s)
- 0 Thread(s)
Best way to check if record exists.
I have been using mysql_numrows($sql) and checking the count to do an insert or update.
A while back r937 implied it was the most inefficient way to do things.
Two things come up on a regular basis, insert or update and check if a record exists. So to get away from mysql_numrows($sql) to insert or update, should I be using,
IF(COUNT(*) > 0, 'OK', 'Failed') as Status
username = 'loren' ;
INSERT INTO users SET username = 'loren', text='hello' ;
ON DUPLICATE KEY UPDATE Status = 'loren'
name | attribute
loren | max_session_time
loren | max_bandwidth_down
loren | max_bandwidth_up
In this case is the first option recommended?
The second question is to just see if a record exists, would the first option be the best or would SELECT DISTINCT be better?
I'm still Googling and found (just copied and pasted)
REPLACE INTO `transcripts`
SET `ensembl_transcript_id` = 'ENSORGT00000000001',
`transcript_chrom_start` = 12345,
`transcript_chrom_end` = 12678;
Many thanks, there is a lot of info out there and many ways of doing things so I hope someone can set me down the right path.
Oops, thought I was in the mysql forum, posted in the wrong place.
Last edited by lorenw; May 3, 2009 at 09:46.What I lack in acuracy I make up for in misteaks