NOTE: This is not a duplicate of my other question . I have changed the table structure and need new help with a new query.
So basically I’m getting notifications of new content on my website. I have 4 tables –
- articles
- media
- updates
- comments
Each table has a set of its own columns (I can include these if anyone wants). In my new notification system I am designing, I determine the newest content, by its timestamp. The timestamp value is an integer formatted to Unix Time.
I have just changed my table structure, before, my tables all had columns that were similar. An example, both articles and media had the column id. The SQL code I was using was this –
SELECT a.*,m.*,u.*,c.* from articles AS a
LEFT JOIN media AS m ON (m.mediaTimestamp = a.timestamp)
LEFT JOIN updates AS u ON (u.updateTimestamp = a.timestamp)
LEFT JOIN comments AS c ON (c.commentTimestamp = a.timestamp)
ORDER BY a.timestamp desc LIMIT 30
However when doing this, the code would return multiple iterations of a column in the same row (it would return an id column for articles and media!). Obviously when I tried to get the data via code, it would give me data for different tables (instead of giving me the article id, it would give me the media id).
My solution to this was to ‘pretty’ up my code and name all columns in a table (such as articles) with their table prefix (so id would become articleID). However now the above SQL is producing errors. Could someone ‘convert’/restructure this SQL for me.
try this: