Database schema (posgresql):

Student(id, name, last_name, e_mail) Teacher(id, name, last_name, e_mail, subject) 

It is necessary:

Print all ' last_name ' and ' name ' of all ' Teacher ' and ' Student ' with a ' type ' field (student or teacher). Sort alphabetically by ' last_name '. It should look like this:

 last_name | type | Kankava | teacher Smith | student Sidorov | teacher Petrov | teacher 

I don’t understand how to add a TYPE column to SELECT and link it to a table?

  • Elementary. Read the book "Understanding SQL" (Undershtanding SQL) - Sergey

1 answer 1

 SELECT * FROM (SELECT name, last_name, 'student' AS type FROM Student UNION SELECT name, last_name, 'teacher' AS type FROM Teacher) AS forexempl ORDER BY last_name;