| Author |
Topic |
|
bobshishka
Yak Posting Veteran
72 Posts |
Posted - 2007-11-19 : 11:37:57
|
| I have 5 tables in the same database named the following: do, name, olm, image, person, scrThey are all link together by and have the following field in each: FCNI would like to delete the corresponding record in each table where the value of the field 'image_path' in the 'image' table is '999999.jpg'What would the syntax be?delete from do, name, olm, image, person, scrwhere image.image_path = '999999.jpg'innerjoin something????Thanks |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-11-19 : 11:43:14
|
You need to do them individually, replacing table each time with the actual table name:DELETE FROM <table> inner join imageon do.fcn = image.fcnwhere image.image_path='9999999.jpg' Future guru in the making. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
bobshishka
Yak Posting Veteran
72 Posts |
Posted - 2007-11-19 : 11:54:18
|
quote: Originally posted by Zoroaster DELETE FROM <table> inner join imageon do.fcn = image.fcnwhere image.image_path='9999999.jpg'
When I run this:DELETE FROM DOinner join IMAGEon DO.fcn = IMAGE.fcnwhere IMAGE.IMAGE_PATH=' .jpg'I get the following error:Incorrect syntax near the keyword 'inner'. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-11-19 : 12:15:29
|
Ok, try this instead:DELETE FROM DOWHERE FCA in (SELECT FCA from IMAGEWHERE IMAGE.IMAGE_PATH = '999999.jpg') Future guru in the making. |
 |
|
|
bobshishka
Yak Posting Veteran
72 Posts |
Posted - 2007-11-19 : 12:23:32
|
| Zoroaster.... you are the man. Thank you for your help! |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-11-19 : 13:31:42
|
| Use the JOIN syntax instead of the subquery way. Here ya go:DELETE dFROM DO d JOIN [IMAGE] i ON d.fca = i.FCA AND i.IMAGE_PATH = '999999.jpg'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-11-19 : 13:37:34
|
quote: Originally posted by tkizer Use the JOIN syntax instead of the subquery way. Here ya go:DELETE dFROM DO d JOIN [IMAGE] i ON d.fca = i.FCA AND i.IMAGE_PATH = '999999.jpg'Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/
That works, I don't like the syntax though. It seems silly that it doesn't work the way Brett did it, though I guess there is a reason. Future guru in the making. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2007-11-19 : 13:45:35
|
| That's just how deletes and updates work with joins. See BOL for the complete syntax.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/ |
 |
|
|
Zoroaster
Aged Yak Warrior
702 Posts |
Posted - 2007-11-19 : 14:28:59
|
Right i'm not questioning the correctness of the syntax, I am just curious as to why it is not consistent with joins in selects - more of a question to Microsoft really. Future guru in the making. |
 |
|
|
|