
Originally Posted by
design@glyndowe
I am trying to delete rows from one table (virtualdb_bu2) that do not have corresponding rows in another table (mtable)
If that's what you want to do, then why are you using CREATE and ALTER. Those are used to create a new table and to alter the structure of a table respectively.
Do you have to do it in one SQL instruction?
I'm not sure what language you are using, but something like this could work for you
Code:
PSEUDO CODE:
SELECT DISTINCT mlsnum FROM virtualdb_bu2
(use DISTINCT here so you only get one of each occurance.
Otherwise it will try to delect non-existant items that will cause an error)
while (fetch loop) {
found = ...SELECT COUNT(*) FROM mtable_bu2 WHERE ListID=<fetched item>
if (!found) {
DELETE FROM virtualdb_bu2 WHERE mlsnum = <fetched item>
}
}
Bookmarks