Jump to content

mySQL row delete..


mikey3521

Recommended Posts

I have a table with the following values:

 

id    to    from    subject    read

 

with the following info

 

1    2    6          hey!            1

2    2    4        wjat?            1

3    8    5        test!            1

 

the "from" is the users 'id' on a different table, now on running a script, I want it to search this table for any row that has "2" in the from field, so any row with a msg user 2 has sent, and delete it. Heres what I have.

 

("DELETE FROM messages WHERE to=2");

 

It returns no erros, the rest of the script runs, and it dosn't delete the rows??

Link to comment
Share on other sites

subject is OK as a field name.  to, from, and read are all reserved words and you should not use them as field names or table name.  The right way to fix the problem is to avoid using reserved words as names.  The sloppy way is to surround each one with `backticks`.

 

Do it right - see http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Link to comment
Share on other sites

I call it sloppy because 99/100 times people need it to fix a problem caused by using reserved words as field names so it becomes a work-around to overcome their initial lack of thought, care, or knowledge :)

Link to comment
Share on other sites

I see what you mean, but given the context of the table, aren't to and from the most appropriate names for the fields? It seems a whole stack easier to put backticks around the words than change the to msgto and msgfrom to me. Guess thats just personal opinion though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.