Database

MySQL JOIN vs UNION

k9e4h 2017. 2. 15. 14:04

http://iamzombie.tistory.com/35


http://www.slideshare.net/ahmadjamshidhashimi/my-sql-join-union


http://stackoverflow.com/questions/905379/what-is-the-difference-between-join-and-union]


https://www.essentialsql.com/what-is-the-difference-between-a-join-and-a-union/


Both Joins and UNIONS can be used to combine data from two or more tables.

Whereas a join is used to combine columns from different tables, the union is used to combine rows.


http://bywatersolutions.com/2012/12/05/union-or-join-in-my-query/



A UNION works differently, instead of linking two tables it “links” two queries. Let me explain…a UNION is a way to combine the results of two or more queries into one result set. In order for the UNION to work correctly you need to remember a few things:


The queries you are placing into a UNION need to have the same structure, that is, the same number of columns and identical data types for each column. The columns from each query do not need to be named the same, just be similar in nature (text, integer, etc).

The final data set column headings will be the column names designated by the first query in the UNION.

A UNION will default to only showing the DISTINCT rows in the result set. If you want to see every result you need to specify UNION ALL in your SQL statement.

반응형

'Database' 카테고리의 다른 글

샤딩(Sharding)과 파티셔닝(Partitioning)  (0) 2017.02.22
MySQL SUM()  (0) 2017.02.20
MYSQL 날짜 형식  (0) 2017.02.13
SQL 특정 기간 중복 조회하기  (0) 2017.02.07
mybatis selectkey  (0) 2017.02.02