如何在子查询上返回多个?

时间:2015-02-03 12:00:34

标签: mysql

您好我很难完成此查询...

如何获得这些结果?

我有3个表...我只是想这样返回但是我的代码错误地认为子查询只返回1 ...

例如我有这个..

"emergency_codes"
---------------------
| id | name         |
---------------------
|  1 | Fire         |
|  2 | crime        |
|  3 | Medical Need |

"ec_type"
-------------------------------------
| id | ec_id        | type          |
-------------------------------------
|  1 | 1        | eruf              |
|  2 | 2        | eruf              |
|  3 | 3        | eruf              |
|  4 | 2        | police            |
|  5 | 3        | hospital          |
|  6 | 1        | firecontrol       |

我的Expected Result

"rescue_units"
-------------------------------------
| id | name         | type          |
-------------------------------------
|  1 | eruf1        | eruf          |
|  2 | firecontrol1 | firecontrol   |
|  4 | eruf2        | eruf          |
|  8 | firecontrol2 | firecontrol   |

到目前为止,我试过......

SELECT * from rescue_units WHERE type LIKE (SELECT type FROM ec_type WHERE ec_id = (SELECT id FROM emergency_codes WHERE id = 1 ))

0 个答案:

没有答案