I want to do a Full Outer Join in MySQL. Is this possible? Is a Full Outer Join supported by MySQL?
相关问题
- SQL join to get the cartesian product of 2 columns
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
Modified shA.t's query for more clarity:
You don't have FULL JOINS on MySQL, but you can sure emulate them.
For a code SAMPLE transcribed from this SO question you have:
with two tables t1, t2:
The query above works for special cases where a FULL OUTER JOIN operation would not produce any duplicate rows. The query above depends on the
UNION
set operator to remove duplicate rows introduced by the query pattern. We can avoid introducing duplicate rows by using an anti-join pattern for the second query, and then use a UNION ALL set operator to combine the two sets. In the more general case, where a FULL OUTER JOIN would return duplicate rows, we can do this:In SQLite you should do this:
None of the above answers are actually correct, because they do not follow the semantics when there are duplicated values.
For a query such as (from this duplicate):
The correct equivalent is:
If you need for this to work with
NULL
values (which may also be necessary), then use theNULL
-safe comparison operator,<=>
rather than=
.It is also possible, but you have to mention the same field names in select.