Jointure croisée (produit cartésien)
-
SELECT * FROM `a` CROSS
JOIN
`b`;
SELECT * FROM `a`, `b`;
- id_a id_b
- 1 1
- 2 1
- 3 1
- 1 2
- 2 2
- 3 2
- 1 103
- 2 103
- 3 103
- 1 104
- 2 104
- 3 104
Jointure interne
-
SELECT * FROM `a` INNER
JOIN `b`
ON `a`.`id_a`=`b`.`id_b`;
SELECT * FROM `a`, `b`
WHERE `a`.`id_a`=`b`.`id_b`;
(cette syntaxe n’est pas dans la norme ANSI)
- id_a id_b
- 1 1
- 2 2
Jointure externe gauche
-
SELECT * FROM `a` LEFT OUTER
JOIN `b`
ON `a`.`id_a`=`b`.`id_b`;
- id_a id_b
- 1 1
- 2 2
- 3 NULL
Jointure externe droite
-
SELECT * FROM `a` RIGHT OUTER
JOIN `b`
ON `a`.`id_a`=`b`.`id_b`;
- id_a id_b
- 1 1
- 2 2
- NULL 103
- NULL 104
Jointure externe bilatérale (émulé par un UNION)
-
SELECT * FROM `a` LEFT OUTER JOIN `b`
ON `a`.`id_a`=`b`.`id_b`
UNION
SELECT * FROM `a` RIGHT OUTER JOIN `b`
ON `a`.`id_a`=`b`.`id_b`;
- id_a id_b
- 1 1
- 2 2
- 3 NULL
- NULL 103
- NULL 104
[DISTINCT] expression[, …]
FROM table
[WHERE conditions]
[ORDER BY expression [DESC]]
[LIMIT [offset,] nb]
SELECT
[DISTINCT] expression[, …]
FROM table1
[INNER] JOIN table2
ON conditions
[WHERE conditions]
[ORDER BY expression [DESC]]
[LIMIT [offset,] nb]
SELECT
[DISTINCT] expression[, …]
FROM table1
LEFT|RIGHT [OUTER] JOIN table2
ON conditions
[WHERE conditions]
[ORDER BY expression [DESC]]
[LIMIT [offset,] nb]