Concatenar dos tablas por o

oso blanco :

Tengo estas tablas Un texto tiene muchos-muchos artículos writer,line

ttext_obj mesa

test obj
1    text1
2    text2
3    text3
4    text4

text_obj_writers mesa

text writer
1    2
2    3
2    4

text_obj_line mesa

text line
1    2
4    3
1    4

Por lo tanto, quiero recoger las filas de los text_objque tienen en uno reast writero uno line.

Por ahora hice un código como éste.

El text_objID que tiene al menos unawrite

SELECT text.id  FROM `text_obj` text 
inner join text_obj_writers writer 
on writer.obj_id = text.id  group by text.id

//it returns
1
2

El text_objID que tienen al menos unaline

SELECT text.id  FROM `text_obj` text 
inner join text_obj_lines line 
on line.obj_id = text.id  group by text.id

//it returns
1
4

Pero quiero tomar orde éstos

1
2
4

¿Cómo puedo concatenar dos tablas por o?

Gordon Linoff:

utilizar exists:

select o.*
from text_obj o
where exists (select 1
              from text_obj_writers tow 
              where tow.obj_id = o.id
             ) or
      exists (select 1
              from text_obj_lines tol 
              where tol.obj_id = o.id
             ) ;

Esto es mucho mejor que el uso de agregación, ya que no es necesario para eliminar duplicados después de unirse a las mesas.

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=372889&siteId=1
Recomendado
Clasificación