Hi,

I have this mysql query with maybe clear comments.
Please can you help me to correct it?
I think that it is a comprehensible code but it requires many corrections.
and also forgive me for my bad english.

this is my query with the commented code:
Code MySQL:
SELECT log_uname
    IF (
          log_uname = 'new_username',
          /* if true that already exists but it is not a verified username */
          (
             SELECT flag_verified, log_uname
                 /* nested if */
                 IF (
                       (TIMESTAMPDIFF(MINUTE, NOW(), SELECT date_registered FROM users WHERE flag_verified = 0 AND log_uname = 'new_username')<1440),
                        /* if true that shorter than 24 hours */
                        NULL,
                        /* if false */
                        DELETE FROM users WHERE log_uname     = 'new_username'
                        /* if possible in the false clause can I add also the following operation?) */
                        /* INSERT into users SET email           = 'email@new_domain.xxx',
                                              log_uname       = 'new_username',
                                              log_pswrd       = '123456',
                                              date_registered = NOW(),
                                              last_access     = NULL,
                                              flag_verified   = 0,
                                              access_counter  = 0 */
                    )
               FROM users
              WHERE flag_verified = 0 AND log_uname = 'new_username'
           ),
           /* if false. if select doesn't retrieve any given username, insert it as new */
           (INSERT into users SET email           = 'email@new_domain.xxx',
                                  log_uname       = 'new_username',
                                  log_pswrd       = '123456',
                                  date_registered = NOW(),
                                  last_access     = NULL,
                                  flag_verified   = 0,
                                  access_counter  = 0
           )
       )
  FROM users
 WHERE log_uname = 'new_username'



this is the same query with uncommented code if useful:
Code MySQL:
SELECT log_uname
    IF (
          log_uname = "new_username",
          (
             SELECT flag_verified, log_uname
                 IF (
                       (TIMESTAMPDIFF(MINUTE, NOW(), SELECT date_registered FROM users WHERE flag_verified = 0 AND log_uname = 'new_username')<1440),
                        NULL,
                        DELETE FROM users WHERE log_uname     = 'new_username'
                    )
               FROM users
              WHERE flag_verified = 0 AND log_uname = 'new_username'
           ),
           (
            INSERT into users SET email           = 'email@new_domain.xxx',
                                  log_uname       = 'new_username',
                                  log_pswrd       = '123456',
                                  date_registered = NOW(),
                                  last_access     = NULL,
                                  flag_verified   = 0,
                                  access_counter  = 0
           )
       )
  FROM users
 WHERE log_uname = 'new_username'

many thanks really.