I need to perform a query in SQL validating the following:
I have a parent table that is called elemento
and has a field tipoelemento
, and two child tables equipo_computo
and equipo red
, with the fields tipoequipocomputo
and tipoequipored
respectively.
I need to make a query in the database that validates the type of selected element. If the user selected the tipoelemento = equipocomputo
show the tiposdequipodecomputo = "servidor fisico"
. But if you selected the tipoelemento = equipored
show the records with tipoequipored = "Switch LAN"
.
This is the query I'm running:
SELECT DISTINCT e.ID_ELEMENTO , e.NOMBRE
FROM 'pmt_equipos_computo' AS ec, 'pmt_elementos' AS e , 'pmt_equipos_red' AS er
WHERE e.ID_TIPOELEMENTO = @@drpTipoDispositivo
AND (ec.ID_ELEMENTO = e.ID_ELEMENTO OR er.ID_ELEMENTO = e.ID_ELEMENTO)
AND (ec.ID_TIPOEQUIPOCOMPUTO = '2' OR er.ID_TIPOEQUIPORED = '10' );
But it brings me all the elements according to the type of element selected. It is not validating that they are only servers in the case of equipos_computo
or that they are only switches in the case of equipos de red
.