It has 3 tables
-
In the
-
In the
cat_entradas
table I have:id_categoria
andcategoria
. -
And in the
sub_cate_entrada
table I have:id_subcategoria
andsubcategoria
.
entrada
table you have the data: id_entrada
, id_empresa
, id_categoria
and id_subcategory.
I've already got the two ids (category_id and sub_subcategory) in the input table.
Now, I need to get the category and the subcategory in their respective tables. How can I do this in a SQL statement only, or will I have to do 2, one for each table?
<?php
$pdo = conectar();
$this->dataConta=$pdo->prepare("SELECT categoria, subcategoria FROM entrada WHERE id_entrada=:id_entrada AND id_empresa=:id_empresa");
$this->dataConta->bindValue(":id_entrada", 30);
$this->dataConta->bindValue(":id_empresa", 1);
$this->dataConta->execute();
$res = $this->dataConta->fetch(PDO::FETCH_ASSOC);
echo $res['categoria']." - ". $res['subcategoria'];
$pdo = null;