2017-05-14 6 views
3

Ich brauche ein wenig Hilfe. Ich habe drei Tabellen und dort Namen sind Halle, hall_quantified_details und hall_hall_quantified_details, und sie sieht wie folgt aus:Mysql Unterabfrage mit Where-Klausel

Halle

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 

Und ich möchte ba bekommen ck mit Abfrage Namen Wert und Wert für hall_id 1, ich habe Abfrage, aber es gibt mir wieder nur Namen hall_quantified_details_id ... sieht Abfrage wie folgt aus:

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 
); 

i für hall_id bekommen, so wollen zurück 1 aus hall_hall_quantified_details Ergebnis, das wie folgt aussieht: Raum 100; Sitze 500 Sitze.

+0

Sie keine Subquery wollen, können Sie eine 'JOIN' zwischen den Tabellen werden soll. –

Antwort

0

Es ist ein einfaches verbinden:

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

Vielen Dank, ich war wirklich verwirrt, danke @ Gurwinder Singh –

+0

@ MilicaPavlovic - Gern geschehen – GurV