473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Deleting data by comparing to another table

I have an entry form allowing customers to enter up to 15 skus (product
id) at a time, so they can make a multiple order, instead of entering
one sku, then submitting it, then returing to the form to submit the
second one, and so forth.

From time to time, the sku they enter will be wrong, or discontiued, so
it will not submit an order.

Therefore, when they are done submitting their 15 skus through the order
form, I want a list showing them all of those skus that came back blank,
or were not found in the database.

I'm doing this by creating two tables. A shopping cart, which holds all
the skus that were returned, and a holding table, that holds all the
skus that were submitted. I want to then delete all the skus in the
holding page that match the skus in teh cart (because they are good
skus) which will then leave the unmatched skus in the holding table.
I'll then scroll out the contents of the holding table, to show them the
skus that were not found in the database.
(confused yet?)
So what I want to do is have some sql that will delete from the holding
table where the sku = the sku in the cart. I've tried writing this, but
it dosn't work.

I tiried this delete from holding_table where sku = cart.sku

I was hoping this would work, but it dosn't. Is there a way for me to do
this?

Thanks!

Bill
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #1
2 3444
Let me suggest that you have the wrong design to start with. Creating
shopping cart tables and holding tables for each user is not a very
effective design and it doesn't make sense in relational terms.

Create a table for all your shopping carts with an ID for each user/session:

CREATE TABLE ShoppingCarts (cart_id INTEGER, sku INTEGER NOT NULL /*
REFERENCES Products (sku) */, PRIMARY KEY (cart_id,sku))

I would have thought it made sense to validate the SKUs as they are entered
which is what the commented FK constraint does in the above code. If you
want to post-validate the SKUs, leave the FK constraint out and display the
invalid entries with this query (@cart_id is the id for this user/session):

SELECT C.sku AS Invalid
FROM ShoppingCarts AS C
LEFT JOIN Products AS P
ON C.sku=p.sku
WHERE C.cart_id = @cart_id AND P.sku IS NULL

You can delete the invalid SKUs like this:

DELETE
FROM ShoppingCarts
WHERE cart_id = @cart_id
AND NOT EXISTS
(SELECT *
FROM Products
WHERE sku = ShoppingCarts.sku)

--
David Portas
------------
Please reply only to the newsgroup
--
Jul 20 '05 #2
AWESOME, David! Thank you.

Bill

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Fughal | last post by:
Hi, I have a big DB2 database and I need this database without any Data in it for testing something. I have made a backup of these db and restore it on a testing system. My Problem is now how...
1
by: Mark | last post by:
This question refers to a main form with a continuous form subform. After an error occurs after entering several records in the subform, how can I delete all the data in the main form and all the...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
46
by: DP | last post by:
hi, i've got a form, with a subform in it. i've got a delete button in the subform. the code i;ve got is; Private Sub cmdDeleteRecord_Click() msg = "Are you sure you want to delete this...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
20
by: hippomedon | last post by:
Hello everyone, I'm looking for some advice on whether I should break the normalization rule. Normally, I would not consider it, but this seems to be a special case. I have created an...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
1
by: jignasha1234567 | last post by:
hi, how can i delete data from one table which is similar to another data in another table having same coloumn name. suppose i have one table name test1 and another table named test2 . ...
2
by: jodleren | last post by:
Hi! In a system, which collects data and the summarises it, we collect a large amount of data. Now, there seems to be a problem, when we try to delete just 16000 rows (entire table btw) or some...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.