You can use a LEFT JOIN
starting with the devices
table:
SELECT i.field1, i.field2, d.floor_id
FROM devices d LEFT JOIN
info i
ON i.floor_id = d.floor_id
WHERE d.device_uuid = 'foo'
What does this return?
- If there is a match between the tables, then it returns the rows with a non-NULL third column.
- If there is a device in
devices
, but no match in info
, then it returns a row with the first two columns as NULL
.
- If there is no device in
devices
, then it returns no rows.
I think this satisfies what you need -- to distinguish these three cases.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…