Search code examples
mysqlpgadmin-4

create a table based on other tables


I have 4 different tables:

student: sid, name, gender 

grades: sid, grade

address: postcode, sid, distance_to_school

health_condition: sid, health_code

Now I want to make a new table that contains all of the columns that I mentioned above. I need to join them based on the sid. I tried to add columns separately but the code is really long. So is there another way to do this task?


Solution

  • If you want to show the data from the fifth table that you want to create, I think with the query is better, so you don't need the fifth table. Just

    "SELECT * FROM student s
    INNER JOIN grades g
    on s.sid = g.sid
    INNER JOIN address a
    on s.sid = a.sid
    INNER JOIN health_condition h
    on s.sid = h.sid
    ORDER BY sid ASC";