0
So, I have a question, how to make a query related between 3 tables, being:
Tabela 1:
Nome: tb_os
Campos: id_os, id_cliente, valor_os
Tabela 2:
Nome: tb_clientes
Campos: id_cliente, endereco_cliente, tel_cliente
Tabela 3:
Nome: tb_status_os
Campos: id_status_os, id_os, status_os
Table number 3, will contain at least 3 status tied to one, can be: Open, Bench, Released.
Which doubt?
I need to make a query relating the 3 tables, however, because of the table tb_status_os, will be returned for each query 3 lines or records, what I need is to group in a row for each O.S. (table 1), and the result brought from table 3, is only the last, being the current status.
I tried so many ways:
SELECT * FROM tb_os AS a
INNER JOIN tb_clientes AS b USING(id_os)
INNER JOIN tb_status_os AS c ON c.ids_os =
(
SELECT MAX(id_os) FROM tb_status_os
ORDER BY id_status_os DESC
)
GROUP BY a.id_os;
Returns the records grouped correctly, but does not return the last record of table 3 ( ex.: Released), for each 1 of table 1, always returns the first of table 3 (e.g.: Open).
Could you help me in this sense?
Thank you!
Hello, I’m starting now in the area, but let’s see if I understand your doubt, you want to search in all Tables, but want the found result of tb_os, tb_clients, tb_status_os be shown all in one line?
– Eorihs
Hello, all right? Then as the INNER JOIN will bring several results, they need to be grouped. However the result table status,!
– INOVAARTE TECNOLOGIA