0

I tried to delete a joining tables with the same lbhc_lb_sku in table lif_bookhascategory and lb_sku in table lif_books. I can't delete it.

Here's my SQL command:

DeleteCommand="DELETE FROM lif_books FROM lif_books CROSS JOIN lif_bookshascategory WHERE (lif_books.lb_sku = @lb_sku) AND (lif_bookhascategory.lbhc_lb_sku = @lb_sku)">

That returns:

Incorrect syntax near the keyword 'INNER'. 
2
  • Can you give more detail on the action you want to perform? Thanks. Commented Apr 1, 2011 at 3:10
  • I tried to delete a joining tables with the same lbhc_lb_sku in table lif_bookhascategory and lb_sku in table lif_books.. Commented Apr 1, 2011 at 3:15

3 Answers 3

2

Officially, the SQL specification does not provide for using a Join in an action query (Insert, Update or Delete). In this case, it is simpler to use a more universal format:

Delete lif_books
Where lb_sku = @lb_sku
    And Exists  (
                Select 1
                From lif_bookhascategory
                Where lbhc_lb_sku = @lb_sku
                )
Sign up to request clarification or add additional context in comments.

Comments

1

I just tested this on my own database and it works.

DELETE lif_bookshascategory, lif_books
FROM lif_bookshascategory
INNER JOIN lif_books
WHERE lbhc_lb_sku = lb_sku

1 Comment

i had two tables lif_bookhascategoy.lbhc_lb_sku and table lif_book.lb_sku
1

This should work:

DELETE lif_bookshascategory, lif_books
FROM lif_bookshascategory
INNER JOIN lif_books 
  ON lif_bookshascategory.lbhc_lb_sku = lif_books.lb_sku

Here's the reference

1 Comment

@SilverFang: Are you using MySQL? I've tested a similar statement on my MySQL' delete test1,test2 from test1 inner join test2 on id1=id2;' and it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.