February 11, 2008 at 1:22 pm
I have the below Select statment and it pulls the records I want to delete from our activity table. How do I turn this select statement into a delete statement? Thank you in advance.
select name.ID,activity_type,log_text from name,activity,name_log
where name.id=activity.id and activity.id=name_log.id
and activity_type like '%ibad%'
and name_log.log_text like '%email%'
and name_log.date_time>activity.transaction_date
and log_text like '%@%>%@%'
and name.email<>activity.description
group by name.id,activity_type,log_text
February 11, 2008 at 1:36 pm
Keeping in mind that you are doing group by in your select (so there are duplicate records being hidden). The fact that you're using the SAME fields in both joins scares me a little as well.
That being said - it looks like the "equivalent" delete statement would be:
delete activity
from name,activity,name_log
where name.id=activity.id and activity.id=name_log.id
and activity_type like '%ibad%'
and name_log.log_text like '%email%'
and name_log.date_time>activity.transaction_date
and log_text like '%@%>%@%'
and name.email<>activity.description
You REALLY ought to switch the join syntax over to ansi-compatible syntax. That could have a big impact on determining what may or may no get picked up by this query.
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
February 11, 2008 at 1:48 pm
I appreciate your help and obviously I'm fairly new at this. I'll have to look more into what you said about ansi-compatable syntax. And why would using the SAME fields in both joins be a bad thing? Sorry for my ingorance.
Thank you,
February 11, 2008 at 2:00 pm
I'm not sure that it is. Some of the less intelligent SQL editors will link things blindly based on fields called the same thing, instead of making sure it really IS related. Of course - I think the relations are probably both based off of the same table, and not two separate parent-child relations on the same field, which might not be quite so odd looking.
that being said - it's not entirely unheard of. I just usually make SURE that's the way it should be, since you're getting ready to delete some data....
----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
February 11, 2008 at 5:59 pm
Hi,
It would be better if you store this SQL query results into Temprary table and use the table to delete the records from activity table.
Thanks -- Vj
February 11, 2008 at 6:29 pm
That's normally the way I do it, too.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply