UNION
puts lines from queries after each other, while JOIN
makes a cartesian product and subsets it — completely different operations. Trivial example of UNION
:
mysql> SELECT 23 AS bah -> UNION -> SELECT 45 AS bah; +-----+ | bah | +-----+ | 23 | | 45 | +-----+ 2 rows in set (0.00 sec)
similary trivial example of JOIN
:
mysql> SELECT * FROM -> (SELECT 23 AS bah) AS foo -> JOIN -> (SELECT 45 AS bah) AS bar -> ON (33=33); +-----+-----+ | foo | bar | +-----+-----+ | 23 | 45 | +-----+-----+ 1 row in set (0.01 sec)
Related Posts:
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- What is the difference between “INNER JOIN” and “OUTER JOIN”?
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What is the difference between UNION and UNION ALL?
- ORA-00904: invalid identifier
- SQL Inner-join with 3 tables?
- Self Join to get employee manager name
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- Why do we need “Relationships” between tables at all?
- How can I do a FULL OUTER JOIN in MySQL?
- Case statement in MySQL
- Difference between JOIN and INNER JOIN
- MySQL Multiple Joins in one query?
- Error Code: 2013. Lost connection to MySQL server during query
- SQL join on multiple columns in same tables
- how to drop partition without dropping data in MySQL?
- 1052: Column ‘id’ in field list is ambiguous
- 1052: Column ‘id’ in field list is ambiguous
- The ALTER TABLE statement conflicted with the FOREIGN KEY constraint
- What is it exactly a BLOB in a DBMS context
- What is semi-join in database?
- The backend version is not supported to design database diagrams or tables
- Simulate CREATE DATABASE IF NOT EXISTS for PostgreSQL?
- Postgres Error: More than one row returned by a subquery used as an expression
- How do I reset a sequence in Oracle?
- How to order by with union in SQL?
- MySQL equivalent of DECODE function in Oracle
- The used SELECT statements have a different number of columns
- what is the difference between triggers, assertions and checks (in database)
- Join vs. sub-query
- Solutions for INSERT OR UPDATE on SQL Server
- “select * into table” Will it work for inserting data into existing table
- Using union and order by clause in mysql
- MySQL Error: : ‘Access denied for user ‘root’@’localhost’
- What’s the best way to search for a UPC code in a Database?
- What is an MDF file? [closed]
- Selecting COUNT(*) with DISTINCT
- Case in Select Statement
- What is a stored procedure?
- SQL WITH clause example [duplicate]
- Unknown column in ‘field list’ error on MySQL Update query
- Unknown column in ‘field list’ error on MySQL Update query
- The wait operation timed out. ASP
- What is SELF JOIN and when would you use it? [duplicate]
- The wait operation timed out. ASP
- Conversion failed when converting date and/or time from character string while inserting datetime
- How do I UPDATE from a SELECT in SQL Server?
- how to fix oracle ORA-01722 invalid number error
- SQL query to select dates between two dates
- What’s the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? [duplicate]
- MySQL – Operand should contain 1 column(s)
- SQL SELECT WHERE field contains words
- Conversion failed when converting date and/or time from character string while inserting datetime
- When should I use CROSS APPLY over INNER JOIN?
- MySQL “CREATE TABLE IF NOT EXISTS” -> Error 1050
- Insert Data Into Temp Table with Query
- MySQL create table if not exists and insert record only if table was created
- error, string or binary data would be truncated when trying to insert
- How to create Temp table with SELECT * INTO tempTable FROM CTE Query
- NOT IN vs NOT EXISTS
- SQL SELECT WHERE field contains words
- Online SQL Query Syntax Checker
- How can I do an UPDATE statement with JOIN in SQL Server?
- Must declare the scalar variable
- ORA-00979 not a group by expression
- ORA-00907: missing right parenthesis
- How do I use properly CASE..WHEN in MySQL
- Must declare the scalar variable
- What is “Advanced” SQL?
- Rename column SQL Server 2008
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- Using group by on multiple columns
- Efficiently convert rows to columns in sql server
- Nested select statement in SQL Server
- INSERT statement conflicted with the FOREIGN KEY constraint – SQL Server
- Using group by on multiple columns
- SQL SELECT WHERE field contains words
- MySQL query String contains
- How do I escape a single quote in SQL Server?
- What’s the difference between VARCHAR and CHAR?
- How to update multiple columns in single update statement in DB2
- T-SQL split string based on delimiter
- How to declare a variable in MySQL?
- How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?
- Finding duplicate values in a SQL table
- ORA-01843 not a valid month- Comparing Dates
- MySQL Cannot Add Foreign Key Constraint
- How do I restore a dump file from mysqldump?
- Drop a temporary table if it exists
- How do I escape a single quote in SQL Server?
- ORA-00918: column ambiguously defined in SELECT *
- Teradata: how to convert varchar value (format ‘dd.mm.yyyy’) to date (format ‘yyyy-mm-dd’ )?
- How Stuff and ‘For Xml Path’ work in SQL Server?
- IDENTITY_INSERT is set to OFF – How to turn it ON?
- SQL update from one Table to another based on a ID match
- Oracle error : ORA-00905: Missing keyword
- How to split the name string in mysql?
- How to reset AUTO_INCREMENT in MySQL
- How do I import an SQL file using the command line in MySQL?
- How do you trouble shoot a “Data type mismatch in criteria expression” error in MS Access 2010?