这是我的疑问:
SELECT id, DeviceName, DeviceTypeId
FROM device
WHERE DeviceTypeId LIKE (SELECT DeviceId FROM net_backupdevice WHERE CustomerId = '1');
执行错误后显示。
错误1242(21000):子查询返回超过1行
此表net_backupdevice返回2条记录,我希望记录信息id,DeviceName,DeviceTypeId存储在设备表中。
所以请帮忙。
答案 0 :(得分:0)
SELECT id, DeviceName, DeviceTypeId FROM device WHERE DeviceTypeId IN (select DeviceId from net_backupdevice where CustomerId = '1');
请注意IN而不是Like
答案 1 :(得分:0)
最简单的修复
SELECT id, DeviceName, DeviceTypeId
FROM device
WHERE DeviceTypeId IN (select DeviceId from net_backupdevice where CustomerId = '1');
可能这是一个正确的版本
SELECT id, DeviceName, DeviceTypeId
FROM device d inner join net_backupdevice nb on d.DeviceTypeId = nb.DeviceId
WHERE nb.CustomerId = 1;