I’ve got the following tables:
| table_one | table_two | table_three | table_four |
| t_one_id | t_two_id | t_three_id | t_four_id | // primary key (auto increment)
| | two_nid | three_nid | four_nid | // foreign key to table_one.t_one_id
| tone_date | ttwo_date | tthree_date | tfour_date | // time this was posted.
// other fields
And the following query,
SELECT `table_two` . * , `table_three` . * , `table_four` . *
FROM `table_two`
JOIN ( `table_three` ) ON `table_three`.`three_nid`=1
JOIN ( `table_four` ) ON table_four`.`four_nid`=1
WHERE `table_two`.`two_nid`=1
And the following data:
table_one: 1, 11/08/2011
table_two: 1, 1, 12/08/2011
table_three: 1, 1, 13/08/2011
table_four: 1, 1, 14/08/2011
Now my query keeps returning zero results, even though but what I am looking for it to return is (when ordered on the date of each table):
result 1: 1 | 1 | 12/08/2011 | // this is from table_two
result 2: 1 | 1 | 13/08/2011 | // from table three
result 2: 1 | 1 | 14/08/2011 | // from four
I have also tried the following but without success:
SELECT * FROM table_two t2, table_three t3, table_four t4 WHERE t2.two_nid = 1 OR t3.three_nid=1 OR t4.four_nid=1;
Where am I going wrong with my SQL queries?
Thanks in advance, if more info needed, don’t hesitate to ask.
If you want to display the results from each table as a seperate row, you’ll need to have three seperate selects, and UNION the results. Try this: