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_obj
que tienen en uno reast writer
o uno line
.
Por ahora hice un código como éste.
El text_obj
ID 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_obj
ID 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 or
de é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.