-1

I have a mysql query that selects a number of records

SELECT
leads.Affiliate_ID,
leads.first_name,
leads.last_name,
leads.email,
leads.loan_purpose,
leads.home_tel,
leads.mobile_tel,
leads.postcode,
leads.house_num,
leads.app_time,
leads.new_application_date,
leads.payment_accepted,
leads.sms
FROM
leads
WHERE
leads.Affiliate_ID =  '23' AND
leads.sms IS NULL  AND
leads.payment_accepted IS NULL  AND
leads.new_application_date < (NOW() - INTERVAL 5 DAY)

how do I now update leads.sms to 1 on all selected records

Any help or suggestions would be great

4

3 回答 3

2

If I understood your question well, try:

UPDATE
leads SET sms = 1
WHERE
Affiliate_ID =  '23' AND
sms IS NULL  AND
payment_accepted IS NULL  AND
new_application_date < (NOW() - INTERVAL 5 DAY)
于 2012-07-02T09:22:16.820 回答
0

Simply replace everything before the WHERE by the standard update syntax :

update leads set sms=1
WHERE
leads.Affiliate_ID =  '23' AND
leads.sms IS NULL  AND
leads.payment_accepted IS NULL  AND
leads.new_application_date < (NOW() - INTERVAL 5 DAY)
于 2012-07-02T09:21:13.660 回答
0

To update the data, you don't need to select the records using select statement. You need to put the condition using WHERE clause as shown below. Using WHERE clause, the records are updated for the row who satisfy that condition.

UPDATE
leads SET sms = 1
WHERE
Affiliate_ID =  '23' AND
sms IS NULL  AND
payment_accepted IS NULL  AND
new_application_date < (NOW() - INTERVAL 5 DAY)

Also in your question at all places you have used leads.FIELD_NAME. When there is one table, you don't need to use table name before field name. Table name is needed when JOINS are used using two or more tables.

于 2012-07-02T10:34:29.863 回答