Select across similar tables
maybe because it's monday, but i'm banging my head against the wall trying to get this to work.
I've got 5 tables, each table has a timestamp field (called datetime) and a message field, all i want to do is pull out the last entry that was added from all the tables put together.
I thought something like this would work:
but it doesn't, it generates this error "Column: 'datetime' in field list is ambiguous", i'm guessing maybe joins are needed but i'm not quite sure how to go about it.
SELECT date_format(datetime, '%D %M %Y %H:%i') as datetime,message FROM (table1,table2,table3,table4,table5,) ORDER BY datetime DESC LIMIT 1
If anyone's got any examples it would be greatly appreciated.