Jump to content

Need Help with Sql IF query


vincej

Recommended Posts

HI - So far I have a query that is not yet complete, but what I have works:

 

UPDATE `referals`
    SET `code` = `code` + 1, `claiment` = $email
    WHERE (customerid=$customerid or `referedemail` = '$referedemail')

 

Now I want to add a conditional clause - this is where  I need help as I am failing miserably.  If the claimant column already contains the email address being offered in the variable $email  then do not update.  If it does not contain the email then update.

 

I'm clueless how to get this done,

 

Many Thanks !

 

 

 

Link to comment
Share on other sites

If the claimant column already contains the email address being offered in the variable $email  then do not update. 

 

If it does not contain the email then update.

 

If you do not have an entry for a user with an email address, you'll be doing an INSERT, not an UPDATE.  So your PHP logic will have to check for the existence of the email first, THEN update or insert accordingly. 

 

But honestly, it's hard to tell what you're doing with no relevant data

Link to comment
Share on other sites

or did you mean the entire update?

 

UPDATE `referals`
    SET `code` = CASE WHEN `claiment` = '$email' THEN `code` ELSE `code` + 1 END, 
    `claiment` = CASE WHEN `claiment` = '$email' THEN `claiment` ELSE  '$email'  END    
    WHERE ((customerid = $customerid) or (`referedemail` = '$referedemail'))

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.