EDIT. I missed the one main issue I was having. I want to display all the unique 'device\_MAC' rows. So I want this query to output 3 rows (as per the original query). The issue I am having is connecting the `data` table to the `remote_node` table via `dt_short` = `rn_short` where the maximum timestamp for `dt_short` in the `data` table.

I am having trouble running a query on 3 tables (2 have many to many relations).

What I am trying to do:

1. Get each distinct `rn_IEEE` from the `remotenodes` table with the maximum timestamp (in the example this will get 3 rows with 3 distinct short addresses `rn_short`)
2. Join with the `devicenames` table on device\_IEEE
3. Get each distinct `dt_short` from the `data` table with the maximum timestamp
4. Join `dt_short` with `rn_short` from the query above

Now the problem I am running into is that I can do the queries for the above individually, I have even gotten the first 3 of them together into a query but I cannot seem to properly join the last bit of data to get the result that I want.

I have been going in circles trying to solve this. Here is a link to SQL Fiddle which contains all the test data and the query as far as I got it, it does what i want for the first line but from table 'data' after the first line is NULL:

[See this SQL fiddle](http://sqlfiddle.com/#!2/ccbe1/64)