2017-05-14 123 views
3

我需要一点帮助。 我有三个表,有名称是大厅,hall_quantified_details和hall_hall_quantified_details,他们看起来是这样的:Mysql子查询与where子句

hall_id | hall_name 
    1  Hall 1 
    2  Hall 2 

hall_quantified_details

hall_quantified_details_id | name_quantified 
      1      space 
      2      seats 

hall_hall_quantified_details

hall_hall_quantified_details_id | hall_id | hall_quantified_details_id | value 
      1       1    1      100m2 
      2       1    2      500seats 

而且我想得到ba具有使用价值和价值查询名称为CK 1 hall_id,我有查询,但它给了我回来只是hall_quantified_details_id的名称...查询看起来是这样的:

SELECT p.name_quantified 
FROM hall_quantified_details p 
WHERE p.hall_quantified_details_id IN (
     SELECT pns.hall_quantified_details_id 
     FROM hall_hall_quantified_details pns 
     WHERE pns.hall_id = 1 
); 

所以我希望找回了hall_id从1 hall_hall_quantified_details结果如下所示:space 100; 500个座位。

+0

你不想子查询,你想要的表之间的'JOIN'。 –

回答

0

这是一个简单的连接:

select h2.name_quantified, 
    h1.value 
from hall_hall_quantified_details h1 
join hall_quantified_details h2 on h1.hall_quantified_details_id = h2.hall_quantified_details_id 
where h1.hall_id = 1; 
+0

非常感谢,我一直对此感到困惑,谢谢@Gurwinder Singh –

+0

@MilicaPavlovic - 不客气 – GurV