我有一个包含这些值的表格:
╔════╦═══════════════╗
║ ID ║ TYPE ║
╠════╬═══════════════╣
║ 1 ║ FUEL PUMP ║
║ 2 ║ FIRE ALARM ║
║ 3 ║ FIRE PUMP ║
║ 4 ║ SAFETY SHOWER ║
╚════╩═══════════════╝
(query is: SELECT DISTINCT TYPE FROM EQUIPMENT)
返回以下内容的查询:
╔═════════════╦══════════════╗
║ Room ║ Equipment ID ║
╠═════════════╬══════════════╣
║ Locker Room ║ 1 ║
║ Hallway ║ 1 ║
║ Foyer ║ 2 ║
║ Office 1 ║ 3 ║
║ Office 2 ║ 2 ║
╚═════════════╩══════════════╝
我试图通过在生成上表的查询的SELECT和WHERE语句中使用子查询来显示EQUIPMENT.TYPE字段。但是,我得到了:ORA-01427: single-row subquery returns more than one row 01427. 00000 - "single-row subquery returns more than one row"
。我认为这是因为EQUIPMENT ID值不止一次返回。
是否可以通过加入来执行此操作?
答案 0 :(得分:0)
select room, type
from equipment join rooms
on rooms.equipment_id = equipment.id
假设另一个表名为ROOMS。