SELECT
<column definition>
FROM
left_table
<JOIN DEFINITION>
right_table
<JOIN CONDITION>
;
SELECT
<column definition>
FROM
left_table
<JOIN DEFINITION>
right_table
<JOIN CONDITION>
<JOIN DEFINITION>
right_table2
<JOIN CONDITION>
...
;
SELECT
<column definition>
FROM
table1
,table2
,table3
WHERE
<join conditions>
;
SELECT
lt.col_1
rt.col_2
FROM
left_table
INNER JOIN
right_table
ON
lt.join_col = rt.join_col
;
SELECT
lt.col_1
rt.col_2
FROM
left_table
INNER JOIN
right_table
USING(join_col)
;
SELECT
t1.*
FROM
table_1 t1
WHERE
t1.some_column IN (SELECT some_other_column FROM table_2)
;
SELECT
t1.*
FROM
table_1 t1
WHERE
EXISTS (SELECT some_other_column FROM table_2 t2 WHERE t2.some_other_column = t1.some_column)
;
SELECT
t1.*
FROM
table_1 t1
WHERE
t1.some_column NOT IN (SELECT some_other_column FROM table_2)
;
SELECT
t1.*
FROM
table_1 t1
WHERE
NOT EXISTS (SELECT some_other_column FROM table_2 t2 WHERE t2.some_other_column = t1.some_column)
;
SELECT
*
FROM
t1
FULL OUTER JOIN
t2
ON
1 = 2
;
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)