Reputation: 117
I have one table "teachers" with a column called 'email', and another table "students" with a column also called 'email'.
I need to show all the e-mails both of the students and the teachers in one single column. That is, one list of all the existing e-mails no matter the position of the owner.
Upvotes: 0
Views: 509
Reputation: 157136
Use a union
:
select email
from teachers
union
select email
from students
It concatenates the two results, and shows the overall distinct values. (In contrary to union all
that can result in duplicate values since all row values are shown, not only the distinct values)
Just a little extra, if you do want to know the origin of the email address, you could do this:
select 'teacher' origin
, id
, email
from teachers
union
select 'student' origin
, id
, email
from students
Upvotes: 1
Reputation: 4189
Use union:
select email from teachers
union
select email from students
Upvotes: 1