Announcement

Collapse
No announcement yet.

SQL Query to delete select users

Collapse
X
Collapse
First Prev Next Last
 
  • Filter
  • Time
  • Show
Clear All
new posts

    SQL Query to delete select users

    We, as most vBulletin Forums, end up with new members who never return and have never posted. I call them 'drive-by registrants'. I already have an SQL Query I use to identify them:
    Code:
    select username, posts, usergroupid, from_unixtime(joindate), from_unixtime(lastvisit) from user where lastvisit = joindate and lastvisit < (unix_timestamp() - (86400 * 730)) and posts = 0 and usergroupid = 2 order by from_unixtime(lastvisit);
    I change the value in (unix_timestamp() - (86400 * 730)) to reflect 'number of years', so:

    1=365 2=730 3=1095 4=1460 5=1825 6=2190 7=2555 8=2920 9=3285 10=3650

    Currently, using 730 (2 years), there are 100 such members. Using higher values, there are none.

    I want to utilize an SQL Query to delete these users and have written this:
    Code:
    delete from user where lastvisit = joindate and lastvisit < (unix_timestamp() - (86400 * 730)) and posts = 0 and usergroupid = 2;
    As this is a permanent action, I'd like a qualified review of what I've written, letting me know if it's okay.
    The Linux Community has given me much. I do what I can to return the favor!

    #2
    It's safer to delete using the AdminCP. There are other tables to update other than the user table.
    Buy me a coffeePayPal QR Code
    My Amazon Affiliate Link
    Fast vBulletin VPS Host:
    This site is hosted by IONOS

    Comment


    • wwdnet
      commented
      Editing a comment
      Relational databases are tricky for finding all the related tables and data. I had the monumental task of mapping a SQL database, and it was a long process.

    #3
    Yeah, but using AdminCP > Users > Prune / Move only allows for 'Has not logged on for x days' (equates to 'Last Activity'). So setting the search to:

    Usergroup: Registered User
    Has not logged on for x days: 730
    Join Date is Before: Todays date
    Posts is less than: 1
    Order By: User Name

    235 users are identified, 135 more than my SQL Query identifies.

    What I'm trying to avoid is having to manually review the Prune / Move results against my SQL Query results.
    The Linux Community has given me much. I do what I can to return the favor!

    Comment


      #4
      Originally posted by Snowhog View Post
      where lastvisit = joindate
      That's where the difference is in your query. You're only looking for users who have joined and last visited on that day they joined. How about those users who logged in the succeeding days but still never posted?
      Buy me a coffeePayPal QR Code
      My Amazon Affiliate Link
      Fast vBulletin VPS Host:
      This site is hosted by IONOS

      Comment


        #5
        Originally posted by glennrocksvb View Post
        How about those users who logged in the succeeding days but still never posted?
        Yes, there are those; lot's of those. But, there are a lot within those who are active; they login but haven't posted. I'm okay with those, if the lastvisit date is 'recent' as compared to their joindate. Nobody's required to post to our forum, and many don't but do login when visiting. It's those who once registered never login again that I want to remove.
        The Linux Community has given me much. I do what I can to return the favor!

        Comment


          #6
          I created a new Usergroup called DriveBys (usergroupid = 67)

          I can use the following SQL to accomplish what I want.

          Code:
          update user set usergroup = 67 where lastvisit = joindate and lastvisit < (unix_timestamp() - (86400 * 730)) and posts = 0 and usergroupid = 2;
          Afterwards, I can delete these users via AdminCP > Users > Prune / Move, specifying Usergroup DriveBys.

          Do you see any issues with this process?​
          The Linux Community has given me much. I do what I can to return the favor!

          Comment


          • glennrocksvb
            commented
            Editing a comment
            That should work.

        Latest Posts

        Collapse

        Working...
        X
        Searching...Please wait.
        An unexpected error was returned: 'Your submission could not be processed because you have logged in since the previous page was loaded.

        Please push the back button and reload the previous window.'
        An unexpected error was returned: 'Your submission could not be processed because the token has expired.

        Please push the back button and reload the previous window.'
        An internal error has occurred and the module cannot be displayed.
        There are no results that meet this criteria.
        Search Result for "|||"