如何从一个表或另一个表中获取同一类型的行以及有关它来自哪个表的信息

Let's say I have tables:

create table people ( 
    human_id bigint auto_increment primary key, 
    birthday datetime );

create table students ( 
    id bigint auto_increment primary key, 
    human_id bigint unique key not null, 
    group_id bigint not null );

create table teachers ( 
    id bigint auto_increment primary key, 
    human_id bigint unique key not null, 
    academic_degree varchar(20) );

create table library_access ( 
    access_id bigint auto_increment primary key, 
    human_id bigint not null, 
    accessed_on datetime );

Now I want to display information about a library access, along with the information whether it was a student or a teacher (and then the id corresponding to the table) (let's say I want something like SELECT access_id,id,true_if_student_false_if_teacher FROM library_access), in an idiomatic way.

How do I form the query (in case such database was already deployed) and what are better and more idiomatic ways to solve that problem (in case it wasn't deployed so far).

MariaDB 5.5, database accessed by Go and nothing else.

Thanks in advance.

You said you need to know which table the data comes from. You can use union all for this:

select la.access_id, s.id, 'Students' as source_table
from library_access la 
    join students s on la.human_id = s.human_id
union all
select la.access_id, t.id, 'Teachers' as source_table
from library_access la 
    join teachers t on la.human_id = t.human_id

Without looking at your tables or any idea as to what you want returned in the select statement:

SELECT  *
FROM    people a,
        students b,
        teachers c,
        library_access d
WHERE   a.human_id = b.human_id
    AND a.human_id = c.human_id
    AND a.human_id = d.human_id