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