Can I delete a entire grouping of rows based off a list of ids?

Posted on 2014-09-21
Medium Priority
Last Modified: 2014-09-26
I'm passing a data value of .... id=1,2,4 to my coldfusion Ajax/cfc function based off a checkboxes marked.

My test data is something like this...

id    cat_id   date
1      1          10-10-1
2      1          10-10-1
3      2          10-10-1
4      1          10-10-1
5      1          10-10-2

I would like it so each time I select the checkboxes that the rows then delete that are not listed in my valuelist i'm passing grouped by date.  I figured a long drawn out way but is there a more streamlined way without writing a few sql statements?

id number 3 should be deleted from the above list so my dataset would then be....

id    cat_id   date
1      1          10-10-1
2      1          10-10-1
4      1          10-10-1
5      1          10-10-2

Thanks for any insight!
Question by:brihol44
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 40336036
CF surely has some way to do this "easily", in SQL I would use

WHERE yourfield NOT IN ( .... )

using the function described in this article :
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40336624
well in cf:

The way you can delete is like this:

<cfquery name="delrecords">
selete from mytable where id in (<cfqueryparam cf_sql_type="cf_sql_numeric" value="#id#" list="yes">)

Open in new window

the above cfquerypatam list attribute will make you are passing a numeric list by comma separator.

check the Type Syntax in adobe Livedocs while using


Author Comment

ID: 40336674
Thx! I think that would work for other cases but I'm wanting to only check against existing ids that are passed and delete the others that don't exist in the passed list but grouped by the date of those values.. So id=1,2,4 are passed but I'd 3 was not. Ids 1.2.3,4 are all apart of the same date of groupings. I thought maybe there was a sub query that could do it in one wiry statement but I'm not sure how to.
LVL 52

Accepted Solution

_agx_ earned 2000 total points
ID: 40337269

> So id=1,2,4 are passed but I'd 3 was not. Ids 1.2.3,4 are all apart of the same date of groupings

There's 2 options:

1. Simplest is to figure out which boxes are NOT checked with javascript. Then pass those id's to the action page, ie  idsToDelete=3

WHERE   YouIDColumn IN 
              <cfqueryparam value="#FORM.idsToDelete#" cfsqltype="cf_sql_integer" list="true">

Open in new window

2. Otherwise, you'd need to tell the db what you mean by "groupings". For example, if you want to delete all records for a specific date - ONLY - then you need to pass a date value - along with your list of id's.


Then use the date value in your query along with the as Angel described. I don't know the data types of your db columns, so adjust the cfsqltypes as needed.

         Remove all records for the specified date that are NOT in #FORM.id# list.
WHERE   YourDateColumn = <cfqueryparam value="#FORM.dateValue#" cfsqltype="cf_sql_date">
AND        YouIDColumn NOT IN 
              <cfqueryparam value="#FORM.id#" cfsqltype="cf_sql_integer" list="true">

Open in new window

That said ... this UI sounds a little confusing. Typically a UI lets users check off what *should* be deleted, rather than "delete everything that is NOT checked"
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 40337284
before you query, you can just the following function of list






you can get the one which fits your needs and then you can store that value in a variable and paass that variable to the database

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, Even though I have created this Tutorial on My personal Blog, Some people might not able to find my website, So here i am posting it again Today, from the topic it is very clear that i will be showing you here the very basic usage of how we …
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question