I'd like to use the sql exists() function but I'm not sure of it's
performance. Every example I've seen does a select * inside the
exists(). Does it really select everything just to return 'true' or
does it just look for a row that exists with the data and return true
once it finds one? If the former than would "select top 1 *" or
"select top 1 id" be more efficient than "select *"

What I'm looking to do is insert some data if the data does not
already exist and then return the ID of the data, either the one that
already exists or the one that will be newly created:

insert into mytable(myname)
select 'michael'
where not exists (
   select * from mytable where myname = 'michael'
)

select id from mytable
where myname='michael'

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion
Archive: http://www.houseoffusion.com/groups/sql/message.cfm/messageid:3436
Subscription: http://www.houseoffusion.com/groups/sql/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/sql/unsubscribe.cfm

Reply via email to