mysql> SELECT * FROM COLABORADOR;
+----+----------+
| ID | NOME |
+----+----------+
| 2 | FULANO 2 |
| 3 | FULANO 3 |
+----+----------+
2 rows in set (0.00 sec)
mysql> SELECT * FROM JORNADA;
+----+---------------------+---------------------+----------------+
| ID | ENTRADA | SAIDA | COLABORADOR_ID |
+----+---------------------+---------------------+----------------+
| 3 | 2017-10-02 10:00:00 | 2017-10-02 19:00:00 | 2 |
| 4 | 2017-10-03 10:00:00 | 2017-10-03 19:00:00 | 2 |
| 5 | 2017-10-04 10:00:00 | 2017-10-04 19:00:00 | 2 |
| 6 | 2017-10-05 10:00:00 | 2017-10-05 19:00:00 | 2 |
| 7 | 2017-10-06 10:00:00 | 2017-10-06 19:00:00 | 2 |
| 8 | 2017-10-02 09:00:00 | 2017-10-02 18:00:00 | 3 |
| 9 | 2017-10-03 09:00:00 | 2017-10-03 18:00:00 | 3 |
| 10 | 2017-10-04 09:00:00 | 2017-10-04 18:00:00 | 3 |
| 11 | 2017-10-05 09:00:00 | 2017-10-05 18:00:00 | 3 |
| 12 | 2017-10-06 09:00:00 | 2017-10-06 18:00:00 | 3 |
+----+---------------------+---------------------+----------------+
10 rows in set (0.00 sec)
mysql> SELECT * FROM INTERVALO;
+----+---------------------+---------------------+----------------+
| ID | ENTRADA | SAIDA | COLABORADOR_ID |
+----+---------------------+---------------------+----------------+
| 11 | 2017-10-02 12:00:00 | 2017-10-02 13:00:00 | 3 |
| 12 | 2017-10-03 12:00:00 | 2017-10-03 13:00:00 | 3 |
| 13 | 2017-10-04 12:00:00 | 2017-10-04 13:00:00 | 3 |
| 14 | 2017-10-05 12:00:00 | 2017-10-05 13:00:00 | 3 |
| 15 | 2017-10-06 12:00:00 | 2017-10-06 13:00:00 | 3 |
| 16 | 2017-10-02 12:00:00 | 2017-10-02 13:00:00 | 2 |
| 17 | 2017-10-03 12:00:00 | 2017-10-03 13:00:00 | 2 |
| 18 | 2017-10-04 12:00:00 | 2017-10-04 13:00:00 | 2 |
| 19 | 2017-10-05 12:00:00 | 2017-10-05 13:00:00 | 2 |
| 20 | 2017-10-06 12:00:00 | 2017-10-06 13:00:00 | 2 |
+----+---------------------+---------------------+----------------+
10 rows in set (0.00 sec)
mysql> SELECT
-> NOME,
-> INTERVALO.ENTRADA AS INTERVALO_ENTRADA,
-> INTERVALO.SAIDA AS INTERVALO_SAIDA
-> FROM INTERVALO
-> JOIN COLABORADOR
-> ON COLABORADOR_ID = COLABORADOR.ID;
+----------+---------------------+---------------------+
| NOME | INTERVALO_ENTRADA | INTERVALO_SAIDA |
+----------+---------------------+---------------------+
| FULANO 2 | 2017-10-02 12:00:00 | 2017-10-02 13:00:00 |
| FULANO 2 | 2017-10-03 12:00:00 | 2017-10-03 13:00:00 |
| FULANO 2 | 2017-10-04 12:00:00 | 2017-10-04 13:00:00 |
| FULANO 2 | 2017-10-05 12:00:00 | 2017-10-05 13:00:00 |
| FULANO 2 | 2017-10-06 12:00:00 | 2017-10-06 13:00:00 |
| FULANO 3 | 2017-10-02 12:00:00 | 2017-10-02 13:00:00 |
| FULANO 3 | 2017-10-03 12:00:00 | 2017-10-03 13:00:00 |
| FULANO 3 | 2017-10-04 12:00:00 | 2017-10-04 13:00:00 |
| FULANO 3 | 2017-10-05 12:00:00 | 2017-10-05 13:00:00 |
| FULANO 3 | 2017-10-06 12:00:00 | 2017-10-06 13:00:00 |
+----------+---------------------+---------------------+
10 rows in set (0.00 sec)
mysql> SELECT
-> NOME,
-> JORNADA.ENTRADA AS JORNADA_ENTRADA,
-> JORNADA.SAIDA AS JORNADA_SAIDA
-> FROM JORNADA
-> JOIN COLABORADOR
-> ON COLABORADOR_ID = COLABORADOR.ID;
+----------+---------------------+---------------------+
| NOME | JORNADA_ENTRADA | JORNADA_SAIDA |
+----------+---------------------+---------------------+
| FULANO 2 | 2017-10-02 10:00:00 | 2017-10-02 19:00:00 |
| FULANO 2 | 2017-10-03 10:00:00 | 2017-10-03 19:00:00 |
| FULANO 2 | 2017-10-04 10:00:00 | 2017-10-04 19:00:00 |
| FULANO 2 | 2017-10-05 10:00:00 | 2017-10-05 19:00:00 |
| FULANO 2 | 2017-10-06 10:00:00 | 2017-10-06 19:00:00 |
| FULANO 3 | 2017-10-02 09:00:00 | 2017-10-02 18:00:00 |
| FULANO 3 | 2017-10-03 09:00:00 | 2017-10-03 18:00:00 |
| FULANO 3 | 2017-10-04 09:00:00 | 2017-10-04 18:00:00 |
| FULANO 3 | 2017-10-05 09:00:00 | 2017-10-05 18:00:00 |
| FULANO 3 | 2017-10-06 09:00:00 | 2017-10-06 18:00:00 |
+----------+---------------------+---------------------+
10 rows in set (0.00 sec)
How to do a select merge while keeping the day in line. Example
+----------+---------------------+---------------------+---------------------+---------------------+
| NOME | JORNADA_ENTRADA | INTERVALO_ENTRADA | INTERVALO_SAIDA | JORNADA_ENTRADA |
+----------+---------------------+---------------------+---------------------+---------------------+
| FULANO 2 | 2017-10-02 10:00:00 | 2017-10-02 12:00:00 | 2017-10-02 13:00:00 | 2017-10-02 19:00:00 |
| FULANO 2 | 2017-10-03 10:00:00 | 2017-10-03 12:00:00 | 2017-10-03 13:00:00 | 2017-10-03 19:00:00 |
| FULANO 2 | 2017-10-04 10:00:00 | 2017-10-04 12:00:00 | 2017-10-04 13:00:00 | 2017-10-04 19:00:00 |
| FULANO 2 | 2017-10-05 10:00:00 | 2017-10-05 12:00:00 | 2017-10-05 13:00:00 | 2017-10-05 19:00:00 |
| FULANO 2 | 2017-10-06 10:00:00 | 2017-10-06 12:00:00 | 2017-10-06 13:00:00 | 2017-10-06 19:00:00 |
| FULANO 3 | 2017-10-02 09:00:00 | 2017-10-02 12:00:00 | 2017-10-02 13:00:00 | 2017-10-02 18:00:00 |
| FULANO 3 | 2017-10-03 09:00:00 | 2017-10-03 12:00:00 | 2017-10-03 13:00:00 | 2017-10-03 18:00:00 |
| FULANO 3 | 2017-10-04 09:00:00 | 2017-10-04 12:00:00 | 2017-10-04 13:00:00 | 2017-10-04 18:00:00 |
| FULANO 3 | 2017-10-05 09:00:00 | 2017-10-05 12:00:00 | 2017-10-05 13:00:00 | 2017-10-05 18:00:00 |
| FULANO 3 | 2017-10-06 09:00:00 | 2017-10-06 12:00:00 | 2017-10-06 13:00:00 | 2017-10-06 18:00:00 |
+----------+---------------------+---------------------+---------------------+---------------------+