SQL JOIN HELP
Posted: 2019-03-22 19:43
I need help optimize the sql
I'm in a custom page,
I'm getting this array of result from a sql call
$res = sql("SELECT tipologia_intervento, COUNT(*) FROM dt_reg_interventi GROUP BY tipologia_intervento", $eo);
tiplogia_intervento is a foreign key
so, then I need to make a for lop of the array result since I have a foreign key here
$fk_intervento = $rows[$x][0];
$intercetta_label = sqlValue("SELECT descrizione_tip FROM dt_tip_intervento where id_tip_intervento='{$fk_intervento}'");
this work, it's also fast, and for how is made the request I don't have many rows, since I simply count the tiplogy, I coudl have max 10 rows
nevertheless I suspect I can get directly the foreign key writing a left join sql query inside the first request
only, I dont' know how to write it correctly in case you need to add count function
I'm in a custom page,
I'm getting this array of result from a sql call
$res = sql("SELECT tipologia_intervento, COUNT(*) FROM dt_reg_interventi GROUP BY tipologia_intervento", $eo);
tiplogia_intervento is a foreign key
so, then I need to make a for lop of the array result since I have a foreign key here
$fk_intervento = $rows[$x][0];
$intercetta_label = sqlValue("SELECT descrizione_tip FROM dt_tip_intervento where id_tip_intervento='{$fk_intervento}'");
this work, it's also fast, and for how is made the request I don't have many rows, since I simply count the tiplogy, I coudl have max 10 rows
nevertheless I suspect I can get directly the foreign key writing a left join sql query inside the first request
only, I dont' know how to write it correctly in case you need to add count function