MYSQL - Concatenate two tables

后端 未结 4 1112
时光说笑
时光说笑 2020-12-11 04:05

I have two tables as follows:

    TABLE A                    TABLE B
 StuID | actid              FacID | actid
  3       12                  98      17
  5           


        
相关标签:
4条回答
  • 2020-12-11 04:46

    You can concatenate these two tables by using select, from and where.

    0 讨论(0)
  • 2020-12-11 04:50
    select * from table_a where actid = 17
    union all
    select * from table_b where actid = 17
    

    You may (or may not) need to do something about the ids not being unique, such as

    select 'Student', table_a.* from table_a where actid = 17
    union all
    select 'Faculty', table_b.* from table_b where actid = 17
    
    0 讨论(0)
  • 2020-12-11 05:03

    You want UNION ALL:

    (SELECT * FROM tablea) UNION ALL (SELECT * FROM tableb)

    I think those parenthese are correct. I remember MySQL being fussy about this.

    0 讨论(0)
  • 2020-12-11 05:12

    its too easy select tableA.stuId,tableA.actId, tableB.facId,tableB.actId from tableA,tableB where tableA.actid=tableB.actid;`

    0 讨论(0)
提交回复
热议问题