Ver Mensaje Individual
  #5 (permalink)  
Antiguo 06/01/2015, 10:04
felipe12357
 
Fecha de Ingreso: junio-2010
Mensajes: 168
Antigüedad: 13 años, 10 meses
Puntos: 3
Respuesta: join con una vista no muestra los campos null

gonzalo, la vista fue probada asi:

Código MySQL:
Ver original
  1. select DISTINCT e.nit,f.total total,e.entidad
  2. from entidades e
  3. (SELECT nit,1 as total
  4.  FROM entidades
  5.  where nit not in (select DISTINCT nit from cotizaciones)
  6.             and nit not in (select DISTINCT nit from convenios)
  7. and nit!='' and nit!=0) as f
  8. on e.nit=f.nit

al momento de probarla, la vista previa muestra los resultados correctos y funciona bien (trae todos los null). pero al momento de guardarla me saca el error: views's slect contains a subquery in from clause

por tal motivo decidí crear esta subconsulta en una vista y el codigo para ello fue el anterior:
Código MySQL:
Ver original
  1. SELECT nit,1 as total
  2.  FROM entidades
  3.  where nit not in (select DISTINCT nit from cotizaciones)
  4.             and nit not in (select DISTINCT nit from convenios)
  5. and nit!='' and nit!=0
y la llame: vw_rojof

y finalmente para terminar (eso pensaba yo) hize el join entre la vista recien creada con el codigo restante:

Código MySQL:
Ver original
  1. select DISTINCT e.nit,f.total total,e.entidad
  2. from entidades e
  3. LEFT JOIN vw_rojof f
  4. on e.nit=f.nit
  5. WHERE true OR f.nit IS NULL #esta es la linea q tu me sugeriste

Pero al hacerlo de esta forma no me trae los campos null.

Espero haber sido claro sobre todo el proceso que he hecho. muchas gracias por tu ayuda