1
I have two tables
Table 1
create table tb1
(
cd_tb1 INT NOT NULL AUTO_INCREMENT PRIMARY KEY
);
Table 2
create table tb2
(
cd_tb2 INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
cd_tb1 int,
vl_avaliacao int,
constraint fk_tb1
foreign key (cd_tb1)
references tb1 (cd_tb1),
);
tb2
can have multiple lines with the same code that belong to tb1
. I need to make a field average vl_avaliacao
and then return the data from tb1
ordered by that average. I wonder if you have any way to do this in Mysql or if I need to return the disordered values and try somehow sort in the application.
The table
tb1
Do you have any other fields besides id? Ideally you would mount the skeleton of your select and then fix the errors. Note: it is perfectly possible to sort directly in mysql– ayrton
yes, I only put the cd to leave as an example
– Evandro Ignacio
How about using the GROUP BY and ORDER BY options?
– anonimo
How to use in this context ?
– Evandro Ignacio
As I said above I need to order the return of tb1 by the average of a field of tb2
– Evandro Ignacio