[Á°][¼¡][ÈÖ¹æ½ç°ìÍ÷][¥¹¥ì¥Ã¥É°ìÍ÷]

mysql:4293

From: (±óÆ£ ½Ó͵) <<endo_t@xxxxxxxxxx>>
Date: Mon, 10 Sep 2001 22:07:42 +0900
Subject: [mysql 04293] Re: £²¥Æ¡¼¥Ö¥ë´Ö¤ÇÉÔ°ìÃפΥǡ¼¥¿¤òÃê½Ð¤·¤¿¤¤¡ª

±óÆ£¡÷²£Æþ¤ê^^; ¤Ç¤¹¡£

moeru@xxxxxxxxxx ¤µ¤ó¤Ï½ñ¤­¤Þ¤·¤¿:
>­¡SELECT DISTINCT user.userid 
>¡¡FROM table1 LEFT JOIN table2 ON table1.userid=table2.userid,user 
>¡¡WHERE table1.userid <> table2.userid
>
>­¢SELECT DISTINCT user.userid 
>¡¡FROM table1 LEFT JOIN table2 ON table1.userid=table2.userid,user 
>¡¡WHERE table2.userid is null

¤Ê¤¼¡¢DISTINCT ¤ò»È¤¤¤¿¤¤¤Î¤«¡¢¤Ã¤Á¤å¤¦¤Î¤Ï¤ª¤¤¤È¤¤¤Æ¡£¡£¡£¡£^^;

>¡Ötable1¤Çtable2¤ËÆþ¤Ã¤Æ¤¤¤Ê¤¤userid¤òÃê½Ð¤·¤¿¤¤¡£¡×
>¤Î¾ì¹ç¡¢­¢¤¬Àµ¤·¤¤½ñ¤­Êý¤Ã¤Æ¤Î¤ÇLEFT JOIN¤ÎÍý²ò¤¬¤Þ¤¹¤Þ¤¹Æñ¤·¤¯¤Ê¤Ã¤Æ¤·¤Þ¤¤¤Þ¤·¤¿¡£¡£

¤³¤ì¤Ï¡¢WHERE ¶ç¤È¤« DISTINCT ¶ç¤òÈ´¤¤¤Æ¥Ç¡¼¥¿¤ò¸«¤Æ¡¢select
¤¹¤ë¥Õ¥£¡¼¥ë¥É¤ò * ¤Ë¤·¤Æ¤ß¤ë¤È°ã¤¤¤¬Ê¬¤«¤ë¤È»×¤¤¤Þ¤¹¡£

¤½¤ì¤è¤ê¡¢¤³¤Î sql ¤Î°ÕÌ£¹ç¤¤¤¬¤Á¤ç¤Ã¤Èʬ¤«¤é¤Ê¤¤¤Ç¤¹¡£^^;
user.userid ¤È table1.userid ¤È table2.userid ¤Î´Ø·¸¤Ï¡©
ÉáÄÌ¡¢¤³¤ó¤Ê´¶¤¸¤Ç¤·¤ç¤¦¡£

mysql> create table table1 ( userid int );
Query OK, 0 rows affected (0.11 sec)

mysql> create table table2 ( userid int, user char(20) );
Query OK, 0 rows affected (0.11 sec)

mysql> insert into table1 values ('1');
Query OK, 1 row affected (0.00 sec)

mysql> insert into table1 values ('4');
Query OK, 1 row affected (0.00 sec)

mysql> insert into table2 values ('1', 'User1');
Query OK, 1 row affected (0.00 sec)

mysql> insert into table2 values ('2', 'User2');
Query OK, 1 row affected (0.00 sec)

mysql> insert into table2 values ('3', 'User3');
Query OK, 1 row affected (0.00 sec)

mysql> select * from table1;
+--------+
| userid |
+--------+
|      1 |
|      4 |
+--------+
2 rows in set (0.00 sec)

mysql> select * from table2;
+--------+-------+
| userid | user  |
+--------+-------+
|      1 | User1 |
|      2 | User2 |
|      3 | User3 |
+--------+-------+
3 rows in set (0.00 sec)

mysql> select * from table1 left join table2 on table1.userid=table2.userid;
+--------+--------+-------+
| userid | userid | user  |
+--------+--------+-------+
|      1 |      1 | User1 |
|      4 |   NULL | NULL  |
+--------+--------+-------+
2 rows in set (0.00 sec)

¤³¤Î·ë²Ì¤«¤é¡¢table2.userid ¤¬ null ¤Ç¤¢¤ë table1.userid ¤¬
Íߤ·¤¤¥Ç¡¼¥¿¤Ê¤Î¤Ç¡¢

mysql> select table1.userid from table1 left join table2
    -> on table1.userid=table2.userid
    -> where table2.userid is null;
+--------+
| userid |
+--------+
|      4 |
+--------+
1 row in set (0.01 sec)

¤È¤¤¤¦¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

>Æ°¤¤¤Æ¤·¤Þ¤¦¤È¡¢¤½¤ì¤¬Àµ¤·¤¤¤È»×¤Ã¤Æ¤·¤Þ¤Ã¤Æ»È¤Ã¤Æ¤·¤Þ¤¤¤Þ¤¹(^^;

SQL ¤ÏÀµ¤·¤¯µ­½Ò¤·¤Æ¤ª¤¯Êý¤¬°ÂÁ´¤Ê¤Î¤Ç¡¢¤³¤Þ¤á¤Ë¥Á¥§¥Ã¥¯
¤·¤Ê¤¤¤ÈÂÌÌܤǤ¹¤Í¡£
¤³¤ì¡¢»ä¤â¤è¤¯¤Ï¤Þ¤ê¤Þ¤¹¡£^^;

[Á°][¼¡][ÈÖ¹æ½ç°ìÍ÷][¥¹¥ì¥Ã¥É°ìÍ÷]

      4270 2001-09-03 16:18 ["yasushi fujiwara" <] £²¥Æ¡¼¥Ö¥ë´Ö¤ÇÉÔ°ìÃפΥǡ¼¥¿¤òÃê½Ð¤·¤¿¤¤¡ª
      4271 2001-09-03 16:54 ¨²[<endo_t@xxxxxxxxxx> ]                                       
      4272 2001-09-03 17:52 ¨²[madara <madara@xxxxx]                                       
      4273 2001-09-03 19:39 ¨­¨±["yasushi fujiwara" <]                                     
      4274 2001-09-03 19:54 ¨­¡¡¨²[fuji <fujiyama@xxxxx]                                   
      4277 2001-09-03 21:49 ¨­¡¡¨±[<endo_t@xxxxxxxxxx> ]                                   
      4278 2001-09-03 23:02 ¨­¡¡¡¡¨±["yasushi fujiwara" <]                                 
      4289 2001-09-09 08:15 ¨­¡¡¡¡¡¡¨±[<moeru@xxxxxxxxxx>  ]                               
      4290 2001-09-10 13:08 ¨­¡¡¡¡¡¡¡¡¨²[fuji <fujiyama@xxxxx]                             
      4292 2001-09-10 21:23 ¨­¡¡¡¡¡¡¡¡¨­¨±[<moeru@xxxxxxxxxx>  ]                           
->    4293 2001-09-10 22:07 ¨­¡¡¡¡¡¡¡¡¨­¡¡¨²[<endo_t@xxxxxxxxxx> ]                         
      4294 2001-09-10 22:19 ¨­¡¡¡¡¡¡¡¡¨­¡¡¨²[¤È¤ß¤¿¤Þ¤µ¤Ò¤í <tomm]                         
      4295 2001-09-10 22:41 ¨­¡¡¡¡¡¡¡¡¨­¡¡¨±[fuji <fujiyama@xxxxx]                         
      4298 2001-09-12 00:23 ¨­¡¡¡¡¡¡¡¡¨­¡¡¡¡¨±[<moeru@xxxxxxxxxx>  ]                       
      4291 2001-09-10 13:31 ¨­¡¡¡¡¡¡¡¡¨±[madara <madara@xxxxx]                             
      4275 2001-09-03 19:54 ¨±[Tomohiro 'Tomo-p' KA]