Mysql subquery with where clause

I need help. I have three tables, and there are names: hall, hall_quantified_details and hall_hall_quantified_details, and they look 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 return with the value request name and value for hall_id 1, I have a request, but it only returns me the name hall_quantified_details_id ... The request 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 want to go back to hall_id 1 from the result of hall_hall_quantified_details, which looks like this: space 100; places for 500 places.

+3


source to share


1 answer


This is a simple connection:



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


source







All Articles