0

I know dozen of questions are available here but I have specific issue which I didn't resolve

I have two tables user_bookmarks and highlights.

user_bookmarks contains all the users bookmarks and highlights contains the selected text of particular bookmark.

suppose two users having same bookmarks and both did some highlight texts.

Now user_bookmarks and highlight tables contains two rows of same bokkmark_id.

if one user delete that bookmark then only one row will be deleted from both tables.

I did some query but didn't success.

here is my query

 DELETE FROM user_bookmarks,highlights USING user_bookmarks
 LEFT JOIN highlights ON user_bookmarks.bookmark_id =
 highlights.bookmark_id WHERE user_bookmarks.`user_id` = 39 
 AND user_bookmarks.`bookmark_id`= 1556
9
  • 1
    user a's bookmark on page 12 of book 1 is NOT the same as user b's bookmark on page 12 of book 1. they SHOULD be able to delete them independently. Commented Apr 14, 2015 at 5:06
  • What is you question? Do you want delete only one row from each table, or delete all rows for this bookmark? What's mean field bookmark_id ? is it a page number? May be is better way to do a unique bookmark instead of composite key user_id+bookmark_id Commented Apr 14, 2015 at 5:40
  • I want to delete all rows from user_bookmarks and single row from highlights table. bookmark_id tends to single article and multiple user can have same article, I also given condition for selected user Commented Apr 14, 2015 at 5:47
  • Does table highlights contains user_id? Commented Apr 14, 2015 at 5:53
  • yes both table contains user_id Commented Apr 14, 2015 at 6:05

1 Answer 1

1

In my opinion , accourding to your logic (in comments), you need to join table using composit key user_id,bookmark_id

 DELETE user_bookmarks,highlights  FROM user_bookmarks
 LEFT JOIN highlights ON 
 user_bookmarks.bookmark_id =  highlights.bookmark_id and 
 user_bookmarks.user_id =  highlights.user_id 
WHERE user_bookmarks.user_id = 39 
 AND user_bookmarks.`bookmark_id`= 1556

It delets rows from all rows with user_id=39 and bookmark_id=1556 from both tables

to delete rows from multiple unit to put all tables into delete section

Sign up to request clarification or add additional context in comments.

1 Comment

sorry, I change syntax... I don't have mysql at home therefore can't check syntax

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.