hmm wait you can use the delete query directly ,
if the records are there with that imageid it will delete them if not no rows will be deleted
Main Topics
Browse All Topicshi experts. i am using mysql query to fetch records. i am doing the right join to check that if the record i am retieving has any associated comments and testimonials attached to it:
the query runs oK but i want to delete once it gets confirmed that comments and testimonials do exists:
i am doing like this
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Ok Well the query of Distict IS ok, i tested it, actually it might have misspelled while i was typing it here:
The issue is when i store testimnoials, it store the counts of there are 5 testimonials related to image 33. so when i run the query, it shows the record 5 times. i do not know why?
what i am trying to do is:
when i delete that imageID, it should delete all the testimnoials and comments related to that imageID, there is no limit as to how many testimonial one image can have.
So this is the issue i am facing trouble
what you really need to do is set up proper relationship between your tables so that when a record from Gall table is deleted, associated records from other 2 tables are deleted automatically.
but here's a query that will delete all related records at once - there's no need for multiple queries:
DELETE g.*, c.*, t.*
FROM (gall g LEFT JOIN comm c ON g.ID = c.ImageID) LEFT JOIN testimonials t ON g.ID = t.ImageID
WHERE g.ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer"
Azadi
Your this query:
DELETE g.*, c.*, t.*
FROM (gall g LEFT JOIN comm c ON g.ID = c.ImageID) LEFT JOIN testimonials t ON g.ID = t.ImageID
WHERE g.ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer"
does it will for mysql
and the LEFT JOIN can do the whole work if records exist it delete else it will not right.
so the above query will function like this:
it will delete record from gall table and if any n number of testimonials or comments exists for that specific record it will delete them too.
right
if yes. please write below right and i am gona try it and let u know what happens exactly
Thanks
Business Accounts
Answer for Membership
by: srikanthmadishettiPosted on 2009-09-17 at 05:35:45ID: 25355290
SELECT DISTINCT(ID), gall.* >
>
>
>
testimonials.testID, comm.commID,
from gall
left outer JOIN testimonials ON Gall.ID = testimonials.ImageID
left outer JOIN comm ON Gall.ID = comm.ImageID
where ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer"
is this query working , it missing comma after gall.*
SELECT DISTINCT(ID), gall.*
testimonials.testID, comm.commID,
from gall
left outer JOIN testimonials ON Gall.ID = testimonials.ImageID
left outer JOIN comm ON Gall.ID = comm.ImageID
where ID = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer"
try to dump this query and see .
if yu are getting correctresults
and does one image will havbe only one comment and one testimonail
like one image 1 with id 1 in gall table will have
mulfiple rows in testimonails and comm tables
In simple if you want to delete testimonails and comments of a image id
you candirectly query the testimonails and comm table righ twhyt do you need join
<cfquery name="test">
select imageid from testimonails where imageid = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer"
</cfquery>
<cfif test.recordcount gt 0 >
delete from testimopnails where imageid = <cfqueryparam value="#URL.ID#" cfsqltype="cf_sql_integer"
</cfif>
same for comments too