Skip to main content
Known Participant
February 10, 2011
Question

deleting from 2 different tables

  • February 10, 2011
  • 1 reply
  • 1281 views

HI,

i have a Database with 2 tables that are identical.

products (main product table)

products_update (every morning this one is fill automatically with the list of products)

So i need to insert/update/delete the products

add and update works fine

<cfquery name="update_data" datasource="mydatasource">
    SELECT *
    FROM products_update
    WHERE exists
(select * from products where products.no_client = products_update.no_client AND products.no_stock = products_update.no_stock)
</cfquery>


<cfquery name="insert_data" datasource="mydatasource">
    SELECT *
    FROM products_update
    WHERE not exists
(select * from products where products.no_client = products_update.no_client AND products.no_stock = products_update.no_stock)
</cfquery>

But i cant figure out how to do the query for delete so i created a select query to see the list of products i want to delete but its giving me the list of product to update i'm confuse  🙂  can someone please point out the obvious to me.


<cfquery name="delete_data" datasource="mydatasource">
    SELECT *
    FROM products_update
    WHERE exists
(select * from products where products.no_client = products_update.no_client AND products.no_stock <> products_update.no_stock)
</cfquery>

<cfoutput query="delete_data">

#delete_data.currentrow# : #no_stock# <P>

</cfoutput>

Thank you

This topic has been closed for replies.

1 reply

Inspiring
February 10, 2011

A delete query without a where clause would probably satisfy your requirements.

Gates_001Author
Known Participant
February 11, 2011

Say what ?

Inspiring
February 11, 2011

Which part did you find unclear?