我收到了这样的陈述:
SELECT id FROM laptops
WHERE (hostname = :hostname)
OR (asset_tag = :asset_tag)
OR (serial = :serial) LIMIT 1
基本上我想检查这三个字段中的任何一个都没有匹配。问题是,我得到的匹配不应该是,这使我认为如果其中一个字段在MySQL和被检查的数据中都是空的,则标记为匹配。这听起来不对吗?如果是这样,我如何从匹配过程中排除空值?
答案 0 :(得分:0)
@Gordon:我认为他正在寻找
SELECT id FROM laptops
WHERE (hostname != :hostname)
AND (asset_tag != :asset_tag)
AND (serial != :serial) LIMIT 1
答案 1 :(得分:0)
好的,结果很简单:
SELECT id FROM laptops
WHERE (hostname = :hostname && hostname != '')
OR (asset_tag = :asset_tag && asset_tag !='')
OR (serial = :serial && serial != '') LIMIT 1