mysql:4291
From: madara <madara <madara@xxxxxxxxxx>>
Date: Mon, 10 Sep 2001 13:31:51 +0900
Subject: [mysql 04291] Re: 2テーブル間で不一致のデータを抽出したい!
moeru@xxxxxxxxxx wrote: > 3.23.21 では、以下のSQLでtable1.userid <> table2.useridができていましたが > > SELECT DISTINCT user.userid FROM table1 LEFT JOIN table2 ON table1.userid=table2.userid,user > WHERE user.userid = table1.userid AND table1.userid <> table2.userid > AND table1.itemid = '$itemid' GROUP BY table1.userid ORDER BY RAND() limit $quantity; > > 3.23.40では、table2.userid is null と書かないと結果が0になります。 > > SELECT DISTINCT user.userid FROM table1 LEFT JOIN table2 ON table1.userid=table2.userid,user > WHERE user.userid = table1.userid AND table2.userid is null > AND table1.itemid = '$itemid' GROUP BY table1.userid ORDER BY RAND() limit $quantity; > http://www.mysql.gr.jp/jpdoc/3.23/manual.ja_Problems.html#Problems_with_NULL に「SQL では、 NULL は他の全ての値(たとえ NULL でも)と比較した時に、常に偽になる値です。」 となっているので3.23.40の方が正しい動作ですね。 班石悦夫 madara@xxxxxxxxxx
4270 2001-09-03 16:18 ["yasushi fujiwara" <] 2テーブル間で不一致のデータを抽出したい! 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]