I have a complex query which results in a table which includes a `time` column. There are always two rows with the same `time`:

[![enter image description here](https://i.stack.imgur.com/C8JjW.png)](https://i.stack.imgur.com/C8JjW.png)

The result also contains a `value` column. The `value` of two rows with the same `time` is always different.

I now want to extend the query to join the rows with the same `time` together. So my thought was to join the derived table like this:

```
SELECT A.time, A.value AS valueA, B.value as valueB FROM
(
    OLD_QUERY
) AS A INNER JOIN A AS B ON 
A.time=B.time AND
A.value <> B.value;

```

However, the `JOIN A AS B` part of the query does not work. `A` is not recognized as the derived table. MySQL is searching for a table `A` in the database and does not find it.

So the question is: How can I join a derived table?