Jump to content

[SOLVED] Help needed creating a mysql query


acctman

Recommended Posts

can someone assist me with creating a php/mysql or sql query i can put in phpmyadmin... that will delete picture comments from users that no longer exist on my site.

 

table: rate_members

field: m_id

 

table: rate_picture_comments = rpc

field: com_user

 

Loop through the entire rpc Select 'com_user' (userid) from rate_picture_comments and then go into the rate_members table and see if 'com_user' exist by checking the 'm_id' field. If no match for com_user to m_id is found then process a sql delete row for com_user mysql_query("DELETE FROM rate_pictures_comments WHERE com_user=$id") something like that.

Link to comment
Share on other sites

** Always Backup your Database First **

 

-Start with a SELECT

SELECT FROM rate_picture_comments WHERE com_user NOT IN ( SELECT m_id FROM rate_members )

 

if those are in deed the records you want to delete, then:

DELETE FROM rate_picture_comments WHERE com_user NOT IN ( SELECT m_id FROM rate_members )

Link to comment
Share on other sites

** Always Backup your Database First **

 

-Start with a SELECT

SELECT FROM rate_picture_comments WHERE com_user NOT IN ( SELECT m_id FROM rate_members )

 

if those are in deed the records you want to delete, then:

DELETE FROM rate_picture_comments WHERE com_user NOT IN ( SELECT m_id FROM rate_members )

 

thanks. when i ran the first query in phpmyadmin, i received this error.

#1064 - 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 'FROM rate_picture_comments WHERE com_user NOT IN ( SELECT m_id FROM rate_members' at line 1

 

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.