ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

MS-SQL

Union ๊ณผ Union all, Select Into

๐Ÿ”ฅ fire 2014. 5. 13. 16:33

1. Union ๊ธฐ๋ณธ์ ์œผ๋กœ distinct ๊ฐ€ ์ ์šฉ๋˜์–ด ์ค‘๋ณต๋ฐ์ดํ„ฐ๋Š” ๋‚˜์˜ค์ง€ ์•Š๋Š”๋‹ค.

 

2. Union all  ์œ„์˜ distinct ์—†์ด ๋ชจ๋“  ๋ฐ์ดํ„ฐ๊ฐ€ ๊ฒฐ๊ณผ๋กœ ๋‚˜์˜จ๋‹ค.

 

3. Select Into

SELECT *
INTO [์™ธ๋ถ€db.์ƒˆ ํ…Œ์ด๋ธ”]

FROM Customers;

 

Customers ํ…Œ์ด๋ธ”์˜ ๋‚ด์šฉ์„ ๋ณต์‚ฌํ•ด์„œ ์™ธ๋ถ€db.์ƒˆ ํ…Œ์ด๋ธ”์— Insert ํ•œ๋‹ค.

 

4. ์˜์–ดํ•ด์„์ด ๋งž๋‹ค๋ฉด.. ^^

The SELECT INTO statement can also be used to create a new, empty table using the schema of another. Just add a WHERE clause that causes the query to return no data:

 

SELECT *
INTO newtable
FROM table1
WHERE 1=0;

 

๋ฐ์ดํ„ฐ ์ €์žฅ์—†์ด ํ…Œ์ด๋ธ” ์Šคํ‚ค๋งˆ๋งŒ ๋ณต์‚ฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์œ„์™€ ๊ฐ™์ด...

 

์ฐธ๊ณ  : http://www.w3schools.com/sql/sql_select_into.asp

 

 

'MS-SQL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

์•”ํ˜ธํ™” ์ฒ˜๋ฆฌ์ˆœ์„œ  (0) 2014.10.07
Group by ... Having์ ˆ  (0) 2014.05.13
์กฐ์ธ Join  (0) 2014.05.13
์Šค์œ™๋ธŒ๋ผ์šฐ์ €  (0) 2014.02.26
truncate ์ œ์•ฝ์กฐ๊ฑด ๋•Œ๋ฌธ์— ์•ˆ๋ ๋•Œ  (0) 2014.02.26
๋Œ“๊ธ€