jmsm Posted September 12, 2012 Report Share Posted September 12, 2012 Saludos, tengo una duda a ver si me ayudan: tengo 3 tablas a, b, a_b (tabla intermedia) ya tengo que hacer una consulta que me muestre los datos de a que esten en a_b pero que cumplan una condicion y los datos que no esten en a_b todo eso en una consulta. ojala alguien lo entienda. de antemano gracias Link to comment Share on other sites More sharing options...
xomarx69 Posted September 12, 2012 Report Share Posted September 12, 2012 Hola amigo, a ver si te entendí: select a.* from a, a_b where (a.pk=a_b.apk and a.condicion=condicion) or a.pk not in (select apk from a_b) Eso te muestra los registros que cumplen con (a join a_b + condicion) y los registros de a que no están en a_b Link to comment Share on other sites More sharing options...
Ra Posted September 12, 2012 Report Share Posted September 12, 2012 SELECT a.* FROM a LEFT OUTER JOIN a_b ON a.pk = a_b.pk WHERE (a.condicion = 'condicion' AND a_b.pk IS NOT NULL) OR (a_b.pk IS NULL) Eso trae "todos los registros de a que están en a_b y cumple con la condición = 'condicion' O todos los registros que están en a y que no están en a_b" Salu2. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now