# 1054 - The column 'parte.codigo_componente' in where clause is unknown

1

I have the following problem.

I am executing this sentence:

select descripcion FROM componente
where 
componente.codigo = pieza.codigo_componente AND
pieza.codigo = pieza_equipo.codigo_pieza AND
pieza_equipo.codigo_equipo = equipos.codigo AND
equipos.codigo = 'EQ_1101'

I miss this error:

  

1054 - The column 'parte.codigo_component' in where clause is unknown

The structure of my tables is as follows:

create table componente (
    codigo int not null,
    familia varchar(30) not null,
    descripcion varchar(30) not null,
    stock int not null,
    marca varchar(20) not null,
    primary key (codigo),
)

create table pieza (
    codigo int not null,
    codigo_componente int not null,
    descripcion varchar(30) not null,
    SN int not null,
    proveedor varchar(20) not null,
    primary key (codigo),
    index codigo_componente(codigo_componente),
    foreing key (codigo_componente) reference componente(codigo));
)

create table pieza_equipo (
    codigo_pieza int not null,
    codigo_equipo int not null,
    primary key (codigo_pieza),
    primary key (codigo_equipo),
    index codigo_pieza(codigo_pieza),
    foreing key codigo_pieza reference pieza(codigo));
    index codigo_equipo codigo_equipo 
    foreing key codigo_equipo reference equipo(codigo));
)

create table equipo (
    codigo int not null,
    descripcion varchar(30) not null,
    primary key (codigo),
)

I am not able to find the error ....: (

thanks in advance!

    
asked by aidamf 13.04.2018 в 00:45
source

2 answers

0

What happens is that in the FROM of your sentence you have not declared the table pieza , even if that table exists in your DB you are not referring to it in the query. What you should do is the following:

SELECT componente.descripcion 
FROM componente, pieza, pieza_equipo, equipos
WHERE componente.codigo = pieza.codigo_componente AND
pieza.codigo = pieza_equipo.codigo_pieza AND
pieza_equipo.codigo_equipo = equipos.codigo AND
equipos.codigo = 'EQ_1101'

You declare in FROM all the tables that you are going to relate so that you do not continue to mark the error. Like not to write the entire name of the table you can use an alias to identify the table, leaving your query as follows:

SELECT comp.descripcion 
FROM componente AS comp, pieza AS pza, pieza_equipo AS pzaequip, equipos AS equip
WHERE comp.codigo = pza.codigo_componente AND
pza.codigo = pzaequip.codigo_pieza AND
pzaequip.codigo_equipo = equip.codigo AND
equip.codigo = 'EQ_1101'
    
answered by 13.04.2018 в 01:00
0

You can specify your database at the beginning of your query:

 USE DATABASE
 SELECT descripcion FROM componente
 WHERE componente.codigo = pieza.codigo_componente 
 AND pieza.codigo = pieza_equipo.codigo_pieza 
 AND pieza_equipo.codigo_equipo = equipos.codigo 
 AND equipos.codigo = 'EQ_1101'

Or you specify the database in your FROM (in the call to the tables):

 SELECT descripcion FROM DATABASE.componente C
 WHERE C.codigo = pieza.codigo_componente 
 AND pieza.codigo = pieza_equipo.codigo_pieza 
 AND pieza_equipo.codigo_equipo = equipos.codigo 
 AND equipos.codigo = 'EQ_1101'
    
answered by 01.08.2018 в 00:46