L
L
lotrop2016-10-03 20:36:38
MySQL
lotrop, 2016-10-03 20:36:38

How to get data in data?

Hello. There is a table where there is a property id, id_house house number, znach property value.
Each house has 4 properties. How can I make a query that returns the house number and all 4 of its properties?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2016-10-03
@lotrop

SELECT `t1`.`id_house`, `t1`.`znach`, `t2`.`znach`, `t3`.`znach`, `t4`.`znach`
  FROM (
    SELECT `id_house`, `znach` FROM `table` WHERE `property_id` = :property1
  ) AS `t1`
  JOIN (
    SELECT `id_house`, `znach` FROM `table` WHERE `property_id` = :property2
  ) AS `t2` ON `t2`.`id_house` = `t1`.`id_house`
  JOIN (
    SELECT `id_house`, `znach` FROM `table` WHERE `property_id` = :property3
  ) AS `t3` ON `t3`.`id_house` = `t1`.`id_house`
  JOIN (
    SELECT `id_house`, `znach` FROM `table` WHERE `property_id` = :property4
  ) AS `t4` ON `t4`.`id_house` = `t1`.`id_house`

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question