Jump to content


Photo

MySQL query


  • Please log in to reply
4 replies to this topic

#1 Perad

Perad
  • Members
  • PipPipPip
  • Advanced Member
  • 287 posts

Posted 29 October 2006 - 09:52 AM

This isn't working, i am not sure i quite grasp the concept of deleting from multiple tables.

Basically i want to delete from news the record where id=$id and from news_comments where news_id=$id

Could someone help me fix this query please.

Thanks

"DELETE FROM news,news_comments WHERE news.id='$id', news_comments.news_id=$id"



#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 29 October 2006 - 12:46 PM

Try this:
"DELETE FROM news, news_comments WHERE news.id='$id' AND news_comments.news_id='$id'"

#3 Perad

Perad
  • Members
  • PipPipPip
  • Advanced Member
  • 287 posts

Posted 29 October 2006 - 01:29 PM

Nope the error messages comes back with

Could not connect to MySQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE news.id='10' AND news_comments.news_id='10'' at line 1

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 29 October 2006 - 07:28 PM

I assume your version supports multi-table deletes?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 29 October 2006 - 09:27 PM

Perad, notice that in wildteen88 post there's single quotes around the $id variables. The error you posted seems to indicate that you're missing a single quote (on the right) at the second $id variable.

... right syntax to use near 'WHERE news.id='10' AND news_comments.news_id='10'' at line 1

should be:

... news_comments.news_id='10'







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users