Friday, February 24, 2012

Complex delete query

Is this valid query:
select a.ID_Attachment FROM attachment a
INNER JOIN message_attachment b ON a.ID_Attachment = b.ID_Attachment
INNER JOIN message c ON b.ID_Message = c.ID_Message
WHERE c.ID_SOMETHING = 1
?Assuming that the tables exists, yes. But I don=B4t understand your
subject within this case ?!
HTH, jens Suessmeyer.|||How about this:
DELETE FROM attachment a
INNER JOIN message_attachment b ON a.ID_Attachment = b.ID_Attachment
INNER JOIN message c ON b.ID_Message = c.ID_Message
WHERE c.ID_SOMETHING = 1
Thank you. :)|||On Wed, 23 Nov 2005 19:08:54 +0100, Petar Popara wrote:

>How about this:
>DELETE FROM attachment a
>INNER JOIN message_attachment b ON a.ID_Attachment = b.ID_Attachment
>INNER JOIN message c ON b.ID_Message = c.ID_Message
>WHERE c.ID_SOMETHING = 1
>Thank you. :)
>
Hi Petar,
This is not a valid syntax.
I *think* that you want something like
DELETE FROM attachment
WHERE EXISTS
(SELECT *
FROM message_attachment AS b
INNER JOIN message AS c
ON b.ID_Message = c.ID_Message
WHERE c.ID_SOMETHING = 1
AND attachment.ID_Attachment = b.ID_Attachment)
(untested - see www.aspfaq.com/5006 if you prefer a tested reply)
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

No comments:

Post a Comment