문제

Can't seem to figure this one out. I want to get data from three different tables into one table in my page.

My tables

People
+----+------+--------+------+
| id | name | status | date |
+----+------+--------+------+

House
+----+---------+--------+------+
| id | address | status | date |
+----+---------+--------+------+

Alarms
+----+------+--------+------+
| id | type | status | date |
+----+------+--------+------+

I want to get all data from those three tables where status is 2. How can I do that and get them in one html table ordered by date.

If someone could point me to the right direction that would be awesome.

도움이 되었습니까?

해결책

try this

 SELECT p.id,
        p.name,
        p.status,
        p.date, 
        h.address,
        a.type
 FROM people p
 INNER JOIN House h ON p.id = h.id  //this i just guessed the relation you should make your relation here
 INNER JOIN Alarms a ON h.id = a.id //this i just guessed the relation you should make your relation here
 WHERE p.status =2
 ORDER BY p.date

IF your tables have no relation then try this

 select id,'type' as type,name,'adress' as adress,status,date  from people where status =2
 union
 select id,'type' as type,name,adress,status,date  from House where status =2
 union
 select id,type,name,'adress' as adress,status,date  from people where status =2
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top