Is the following query possible using esqueleto?
DELETE Table1
FROM Table1
INNER JOIN Table2 ON Table1.ID = Table2.ItemID
I've tried:
delete $
from $ \(table1 `InnerJoin` table2) ->
on (table1 ^. Table1ID ==. table2 ^. Table2ItemID)
which, oddly enough, generated one of the only runtime errors I've ever seen in Haskell
ERROR: syntax error at or near "INNER"
LINE 2: FROM "table1" INNER JOIN "table2" ON "tab...
(basically, it was unhappy that the DELETE
was missing the "table1")
I've also tried adding a return value to the monad, which, like with select might add that missing value. But this fails because delete requires a monad of type m ()
.
Is it possible that this is just missing from Esqueleto?
Try this.
delete $
from $ \(table1 `InnerJoin` table2) -> do
on (just (table1 ^. Table1ID ==. table2 ^. Table2ItemID)
I think it is very late to answer this question but you can use EXISTS
DELETE Table1
WHERE EXISTS (SELECT * FROM Table2 WHERE Table1.ID = Table2.ItemID)
In MS SQL you can use you can delete table using join in following manner
DELETE Table1,Table2 FROM Table1 INNER JOIN Table2
WHERE Table1.Id1= Table2.Id1 and Table1.Id1= '1'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.