简体   繁体   中英

Mysql subquery with where clause

i need a little bit of help. I have three tables and there names are hall, hall_quantified_details and hall_hall_quantified_details, and they looks like this:

Hall

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

And i want to get back with query name of value and value for hall_id 1, i have query, but it gives me back only name of hall_quantified_details_id... Query looks like this:

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

So i wish to get back for hall_id 1 from hall_hall_quantified_details result that looks like : space 100; seats 500seats.

It's a simple join:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM