我一直在寻找这个答案。我有两个相同的表,contacts 和 contacts_copy。每个都有全名、公司、街道、城市、州和邮编。如果contacts.street 不为NULL,那么我选择这些项目。如果是,我从重复表中选择这些项目。
SELECT contacts.fullname,
CASE WHEN contacts.street IS NULL
THEN
contacts_copy.Company,
contacts_copy.street,
contacts_copy.city,
contacts_copy.state,
contacts_copy.zip
ELSE
contacts.Company,
contacts.street,
contacts.city,
contacts.state,
contacts.zip
END CASE
FROM contacts_copy, contacts
WHERE contacts.Company = contacts_copy.fullname
AND contacts.kind = 'Person'
ORDER BY contacts.last DESC
I keep getting:
[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
contacts_copy.street,
contacts_copy.city,
contacts_copy.state,
contacts_cop' at line 4
必须有一种更简单的方法来做到这一点。MySQL 错误消息非常无用。
谢谢,
本