Oracle joins
Par Pierrick, vendredi 6 juillet 2007 à 11:56 / categorie: Développement / tags: / #100 / rss

As a reminder for myself, here is a list of join examples using Oracle.
SQL> create table mother_table (id number(5), name varchar2(10));
SQL> insert into mother_table (id, name) values (1,'pierrick');
SQL> insert into mother_table (id, name) values (2,'marion');
SQL> create table daughter_table (mother_id number(5), color varchar2(20));
SQL> insert into daughter_table (mother_id, color) values (2, 'pink');
SQL> insert into daughter_table (mother_id, color) values (3, 'green');
SQL> select *
SQL> from mother_table
SQL> inner join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
SQL> select *
SQL> from mother_table
SQL> join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
SQL> select *
SQL> from mother_table
SQL> left join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
1 pierrick
SQL> select *
SQL> from mother_table
SQL> left inner join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
SQL> select *
SQL> from mother_table
SQL> left outer join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
1 pierrick
SQL> select *
SQL> from mother_table right
SQL> join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
3 green
SQL> select *
SQL> from mother_table
SQL> right inner join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
SQL> select *
SQL> from mother_table
SQL> right outer join daughter_table on mother_id = id
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
2 marion 2 pink
3 green
SQL> select *
SQL> from mother_table
SQL> cross join daughter_table
SQL> ;
ID NAME MOTHER_ID COLOR
---------- ---------- -------------- --------------------
1 pierrick 2 pink
2 marion 2 pink
1 pierrick 3 green
2 marion 3 green
Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.