1
I need the following help from you.
First, see below my current query:
sq1 = mysqli($conexao,"select * from tabela1 TBL1 left join tabela2 TBL2 ON
TBL1.codigo=TBL2.codigoestrangeiro LEFT JOIN tabela3 TBL3 ON
TBL2.codigo=TBL3.codigoestrangeiro
group by TBL1.codigo order by TBL1.codigo desc");
Table 2 and table 3 may contain n records linked to table 1. In this case, how do I call for this information?
And how do I sort the information in a personalized way, IE, table 2 must be displayed in order of name, and table 3 by date.
related: http://answall.com/questions/143668/convertendo-dois-selects-mysql-para-um
– Daniel Omine
Again, as I mentioned in the other question, avoid multiple questions in one. Lei the guide to use the site: http://answall.com/tour
– Daniel Omine
@Danielomine, even if it is two questions, it would not be very creative to create another question just to know how to order a query.
– Marco Souza
Read the site usage guide, please.
– Daniel Omine
@Luis, your select is almost certain, I just don’t know what the need to use the group by?
– Marco Souza
to order:
order by TBL1.codigo desc, TBL2.nome ASC, TBL3.data ASC
– Ivan Ferrer
for
n
records useleft join
, to pick up unique records, useinner join
. Obs: thegroup by
, will group the records, so it will not bring all relations, filtering the other records, will only appear "the first record you find" for each code.– Ivan Ferrer
Hello, Marco, if I don’t use group by, it will repeat records of the same code from table 1. If table 2 has 3 records, it would show the code of table 1 repeated 3 times.
– Luis
I got it Daniel, sorry again.
– Luis