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

MS-SQL

Union ๊ณผ Union all, Select Into

๐Ÿฉท ์Šˆ ๐Ÿงก 2014. 5. 13. 16:33
728x90
SMALL

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

 

 

728x90
LIST

'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
๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
ยซ   2025/03   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
๊ธ€ ๋ณด๊ด€ํ•จ
250x250