I have the following db table (People):
+--------+--------+--------+--------+
| Name |Building| Nr | Time |
+--------+--------+--------+--------+
| Tim | House | 30 | 10:10 |
| Jill | House | 31 | 10:20 |
| Tim | Flat | 31 | 10:30 |
| NULL | Tower | NULL | NULL |
| Jack | Hut | 32 | 10:50 |
| Jane | Cabin | 35 | 10:60 |
| Susan | Cabin | 35 | 11:70 |
+--------+--------+--------+--------+
Now I want to show all Buildings (and the data that comes with it) that Tim owns. I did that like this:
SELECT * FROM `People` WHERE Name="Tim"
Result:
+--------+--------+--------+--------+
| Name |Building| Nr | Time |
+--------+--------+--------+--------+
| Tim | House | 30 | 10:10 |
| Tim | Flat | 31 | 10:30 |
So far so good. The thing is, there are more buildings (Tower, Hut and Cabin). I want to show these too but leave the data (accept the building type) blank.
This result is that I need:
+--------+--------+--------+--------+
| Name |Building| Nr | Time |
+--------+--------+--------+--------+
| Tim | House | 30 | 10:10 |
| Tim | Flat | 31 | 10:30 |
| NULL | Tower | NULL | NULL |
| NULL | Hut | NULL | NULL |
| NULL | Cabin | NULL | NULL |
+--------+--------+--------+--------+
Since Tower was already NULL I can easily extract that one using:
SELECT * FROM `People` WHERE Name="Tim" OR Name is NULL
Result:
+--------+--------+--------+--------+
| Name |Building| Nr | Time |
+--------+--------+--------+--------+
| Tim | House | 30 | 10:10 |
| Tim | Flat | 31 | 10:30 |
| NULL | Tower | NULL | NULL |
+--------+--------+--------+--------+
Problem is, I still miss the Hut and Cabin. Can this even be done with a query? Also tried some options like GROUP BY etc but this gave mixed data in return. Also searched using Google but had no luck.
Hope anyone can help me out!
ps. as a workaround I can add in the db:
| NULL | Hut | NULL | NULL |
| NULL | Cabin | NULL | NULL |
But that will be a immense job to contain this table when you add more buildings
Something like
Can do what you want ?