Reputation: 687
Can I run a query that would perform the following?
Table: users
Columns: username, email
If username is blank/empty, update username with email in that row
Upvotes: 1
Views: 1054
Reputation: 19
This should do it:
UPDATE users
SET username = email
WHERE username = ""
OR username is NULL;
Upvotes: 1
Reputation: 3591
Update users set username = email where username is null or username = ''
Upvotes: 1
Reputation: 27364
UPDATE
users
SET
users.username = users.email
WHERE users.username IS NULL OR LENGTH(users.username)=0;
Upvotes: 0
Reputation: 263723
Assuming by BLANK/EMPTY
means NULL
or nothing,
if you mean you only want to project or SELECT
, use COALESCE
SELECT COALESCE(username, email) username,
email
FROM users
but if you want to permanently update the field,
UPDATE users
SET username = email
WHERE userName IS NULL
Upvotes: 5