title: SQL Query COUNT SELECT
body: <p>I need to generate table as stated below. I have these samples but it doesn't work. Any please help.</p>
  
  <pre>
  SELECT id, room, bed, 
  bed -(SELECT count(bed) FROM tb_student WHERE room_id = id) as FREE
  FROM tb_rooms
  
  tb_rooms
  +----+-------+-----+
  | ID | ROOM  | BED |
  +----+-------+-----+
  |  1 | A111  |  4  |
  |  2 | A112  |  2  |
  |  3 | A113  |  2  |
  |  4 | A114  |  2  |
  +----+-------+-----+
  
  tb_student
  +----+---------+----------+
  | ID | STUD_ID  | ROOM_ID |
  +----+---------+----------+
  |  1 |    211   |  3      |
  |  2 |    212   |  1      |
  |  3 |    213   |  1      |
  |  4 |    214   |  2      |
  +----+----------+---------+
  
  I need something like this...
  +----+-------+------+-----+
  | ID | ROOM  | BED  |FREE |
  +----+-------+------+-----+
  |  1 | A111  |  4   | 2   |
  |  2 | A112  |  2   | 1   |
  |  3 | A113  |  2   | 1   |
  |  4 | A114  |  2   | 2   |
  +----+-------+------+-----+
  
  </pre>