MySQL Forums
Forum List  »  Newbie

Sub query with dynamic parameters
Posted by: Allan Andrade
Date: August 19, 2010 06:03AM

Hello,

I'm needing to create a query with a subselect composed of dynamic fields, ie values that are in the selection.
---
SELECT
c.label_campo
, val_fk
, cmb.*
, (select cmb.campo_des from cmb.tabela where cmb.campo_id = d.val_new)
FROM w_log_evento as e
left join w_log_detalhe as d on d.fk_log_evento = e.cod_log
left join w_campos as c on c.nome_campo = d.campo and c.fk_pagina = e.fk_pagina
left join w_campos_cfg_combo as cmb on cmb.fk_campo = (select c3.cod_campo from w_campos as c3 where c3.fk_pagina = e.fk_pagina and c3.nome_campo = d.campo)
---

I have a table with LOG (w_log_evento), which has details (w_log_detalhe), which in turn has fields of type COMBO (select option in html), which is linked (in one to one relationship) with the configuration table combos (w_campos_cfg_combo).

It works fine without the sub-select, and returns the following:
label_campo, "val_fk", "tabela", "campo_des", "campo_id"
Rubrica, "51", "st_proj_rubrica","des_rubrica", "cod_proj_rubrica"
Fornecedor, "103650", "sv_pes_juridica","completo", "fk_pessoa"


The idea is that it mount a sub-query with the field value table, and campo_des campo_id and bring the return for each line.

Can anyone help?


Grateful to all!

Options: ReplyQuote


Subject
Written By
Posted
Sub query with dynamic parameters
August 19, 2010 06:03AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.