0
good morning,
I need to perform a select of two tables that are related 1 to many:
Table 1: products Table 2: price group
I need to get all prices from the price group table, which may have 1 or more.
In my case of the select below it even takes the most prices repeats all the data as if it were another product, as I can do so that each products already comes with all the prices corresponding to it?
I am using Codeigniter, below the select I am currently using.
$this->db->select('produtos.*, grupo_preco_produtos.grupo_preco_venda');
$this->db->from('produtos');
$this->db->join('grupo_preco_produtos', 'grupo_preco_produtos.id_produto = produtos.id');
$this->db->where(array('produtos.id_empresa' =>$id_empresa, 'produtos.del' => 0, 'produtos.tipo_produto' => 1,));
$query = $this->db->get();
return $query->result();
Have you thought about how you would use it later? Sometimes what you want to do is not the best option and the people here could help you with a better solution.
– Denis
You want to bring them separated by comma?
– Sorack
So Denis I need to put together a list of the products and their prices, I didn’t want to have to have each line have to connect to the database to get the data, I think it might overload the database, because it is an Pr that will have several clients or you think that does not burden the bank
– Clayton Eduardo Mergulhão
Sorack, it can be yes and because at the time of listing I can separate.
– Clayton Eduardo Mergulhão
Yes Denis, I know this may be that what I am doing may not be the best option in case friends have another better option please can pass me without any problem
– Clayton Eduardo Mergulhão
Has any response helped solve the problem and can address similar questions from other users? If so, make sure to mark the answer as accepted. To do this just click on the left side of it (below the indicator of up and down votes).
– Sorack