¾È±Ô °øºÎ¹æ

MS-SQL > Union All

µî·ÏÀÏ : 2017-06-30 17:02 Á¶È¸¼ö : 52,761

Å×À̺í¸í:table1 

------------------------------------- 
number, title, content 
------------------------------------- 
1, ¿¬½À1, ³»¿ë1 
2, ¿¬½À2, ³»¿ë2 
3, ¿¬½À3, ³»¿ë3 

------------------------------------- 
Å×ÀÌºí ¸í:table2 
------------------------------------- 
num,subject,content 
------------------------------------- 
4, ³»¿ë4, ¿¬½À4 
5, ³»¿ë5, ¿¬½À5 
6, ³»¿ë6, ¿¬½À6 

´ÙÀ½°ú °°ÀÌ table1,table2¿¡ °¢°¢ÀÇ °ªÀÌ µé¾î ÀÖÀ»¶§,'¿¬½À'À̶õ ´Ü¾î¸¦ °Ë»öÇÏ°í ½Í´Ù.

¿¹¸¦ µé¾î '¿¬½À'À̶õ ´Ü¾î¸¦ °Ë»öÇßÀ»¶§,,,,

table1.title 
table1.content 
table2.subject 
table3.content

¸¦ ´Ù °Ë»öÇؼ­ Ãâ·ÂÇØ ÁÖ¾î¾ß ÇÒ °æ¿ì°¡ ÀÖÀ» °ÍÀÌ´Ù.. 
ÀÌ·±°æ¿ì ¾Æ·¡¿Í °°Àº union all¹®À» »ç¿ëÇÏ¸é µÈ´Ù. ´Ü, Å×À̺í¸íÀº ¸®ÅÏÇÏÁö ¸øÇÏ´Â ´ÜÁ¡ÀÌ ÀÖ´Ù. 
 

select number, title, content from table1 where title like '%¿¬½À%' or content like '%¿¬½À%' "
union all 
select number, title, content from table2 where title like '%¿¬½À%' or content like '%¿¬½À%'"

Union All Á¤·Ä¹æ¹ýÀº ¾Æ·¡¿Í °°½À´Ï´Ù. Sub Query¸¦ ÀÌ¿ëÇÏ¸é µË´Ï´Ù. 

SELECT A.title, A.content
    FROM (
        SELECT title, content FROM board1
        UNION ALL
        SELECT title, content FROM board2
        ) A
    ORDER BY A.title, A.content


Union AllÀ» ¿¤¸®¾î½º·Î ÀâÀº ´ÙÀ½¿¡ Order by¸¦ »ç¿ëÇÏ¸é µÈ´Ù.
Union All Å×À̺í¸íÀ» ±¸ÇÏ°í ½Í´Ù?
¸¸¾à Å×À̺í¸íÀ» ±¸ÇÏ°í ½Í´Ù¸é ¾î¶»°Ô ÇÏ¸é µÉ±î¿ä? Á¦°¡ ÇÁ·ÎÁ§ Çϸ鼭 Èûµé¾ú´ø ³»¿ëÀε¥ 
ÀÇ¿Ü·Î ³Ê¹«³ª °£´ÜÇÑ ¹æ¹ýÀ» »ý°¢ÇØ ³Â½À´Ï´Ù. ȣȣȣ,,,,µµ¿òÀÌ µÇ½Ã±æ ¹Ù¶ó¸é¼­,,

SELECT A.title,A.tname, A.content
    FROM (
        SELECT title, 'board1' as tname,content FROM board1
        UNION ALL
        SELECT title, 'board2' as tname,content FROM board2
        ) A
    ORDER BY A.title, A.content

¾î¶°¼¼¿ä? ½±Áö¿ä?
¡Ø Ȥ½Ã µµ¿òÀÌ µÇ¼Ì´Ù¸é ´ñ±Û¿¡ ÇѸ¶µð ³²°ÜÁÖ¼¼¿ä!
ÀÛ¼ºÀÚ   ºñ¹Ð¹øÈ£
ÀÚµ¿±Û ¹æÁö     (ÀÚµ¿±Û ¹æÁö ±â´ÉÀÔ´Ï´Ù.)
³»¿ë   ´ñ±Û´Þ±â 
À̸ÞÀÏ ¹®ÀÇ : cak0280@nate.com  
Copyright 2000 By ENTERSOFT.KR All Rights Reserved.