samedi 21 mars 2015

SQL | Joining and renaming databases

I have three tables medlem, funktion and children. I have to join all three tables together and print out everything they say. Medlem and funktion share "ID" as primary key. However the table children has two columns called cid and pid which stands for childrenID and parentID. I think I have to rename cid and pid to "id" so medlem and funktion understand what it is.



SELECT *
FROM medlem
NATURAL JOIN funktion
NATURAL JOIN children
where cid and pid = id;


This is what it prints http://ift.tt/1CIVYSR The thing is it's over 100 members in the database and I only get 11 results. If a member isn't a parent or a child it should be blank, but if they are the child/parent should be listed as a number(id).


English isn't my native language so if you don't understand what I need help with just ask!


Aucun commentaire:

Enregistrer un commentaire