我有两张表如下:
TABLE A TABLE B
StuID | actid FacID | actid
3 12 98 17
5 17 54 21
我想列出参加活动17的每个人,包括学生和教师的名字.无论如何,我可以得到如下结果:
id | actid
98 17
5 17
没有创建一个新表(通过使用表达式嵌套或派生关系)?
在actid上加入会产生类似的结果:
StuID | FacID | actid
5 98 17
我想我需要一种连接形式?
解决方法:
select * from table_a where actid = 17
union all
select * from table_b where actid = 17
您可能(或可能不)需要对不唯一的ID执行某些操作,例如
select 'Student', table_a.* from table_a where actid = 17
union all
select 'Faculty', table_b.* from table_b where actid = 17
标签:mysql,sql,concatenation
来源: https://codeday.me/bug/20190714/1456728.html