Ver Mensaje Individual
  #9  
Antiguo 17-10-2014
orodriguezca orodriguezca is offline
Miembro
 
Registrado: ene 2009
Posts: 221
Reputación: 16
orodriguezca Va por buen camino
Usando Having

Creo que esto funcionaría :

Código SQL [-]
select R1.NROPEDIDO
  from DETPEDIDO R1
  where R1.IDPRODUCTO in ('TORNILLO', 'TUERCA')
  group by R1.NROPEDIDO
  having Count(*) >= 2; -- 2 es elnumero de diferentes idProducto buscados

También se me ocurrió esto otro, que es un poco más rebuscado, pero en ciertas situaciones puede darnos algo de flexibilidad adicional, siempre y cuando nuestro motor de bases de datos pueda realizar consultas CTE (common-table-expresion) (por lo menos Firebird, Sql Server y db2 pueden):

Código SQL [-]
with R1 as (
  select NROPEDIDO
    from DETPEDIDO 
    where IDPRODUCTO = 'TORNILLO'),
R2 as (
  select NROPEDIDO
     from DETPEDIDO
     where IDPRODUCTO = 'TUERCA'
)
select R1.NROPEDIDO
  from R1
  inner join R2
      on R1.NROPEDIDO = R2.NROPEDIDO;
Responder Con Cita