[前][次][番号順一覧][スレッド一覧]

mysql:9368

From: "HIROSE, Masaaki" <"HIROSE, Masaaki" <hirose31@xxxxxxxxxx>>
Date: Fri, 14 May 2004 11:29:34 +0900
Subject: [mysql 09368] Re: distinct でデータ欠落

ひろせといいます

MySQL 4 以上限定ですが、(UNION ALLじゃなくて) UNION は DISTINCT と同じ
作用を持っているので、これを利用すればうまくいくかもしれません。

(select question_no from test order by create_date desc)
union
(select question_no from test where 1<0)
limit 10;

もしくはダミーselectなしで、

(select question_no from test order by create_date desc) limit 10;

でもいけます。

mysql> select * from q order by o desc;
+------+------+
| n    | o    |
+------+------+
|    1 |  101 |
|    1 |  100 |
|   10 |   92 |
|   10 |   91 |
|   10 |   90 |
|   20 |   82 |
|   20 |   81 |
|   20 |   80 |
|   40 |   80 |
|   30 |   70 |
+------+------+
10 rows in set (0.00 sec)

mysql> select distinct n from q order by o desc limit 3;
+------+
| n    |
+------+
|    1 |
|   10 |
|   40 |
+------+
3 rows in set (0.00 sec)

mysql> (select n from q order by o desc) limit 3;
+------+
| n    |
+------+
|    1 |
|   10 |
|   20 |
+------+
3 rows in set (0.00 sec)

ではでは

-- 
ひろせ
http://www.irori.org/

[前][次][番号順一覧][スレッド一覧]

      9354 2004-05-13 23:53 [Koichi Shimamura <ma] distinct でデータ欠落                   
      9355 2004-05-14 00:11 ┗[seiji takegata <take]                                       
      9358 2004-05-14 01:32  ┣["KATAYOSE hakuo" <ka]                                     
      9359 2004-05-14 02:22  ┃┗[seiji takegata <take]                                   
      9360 2004-05-14 02:50  ┗[seiji takegata <take]                                     
      9364 2004-05-14 09:54   ┗[Koichi Shimamura <MA] Re: distinct でデータ             
      9365 2004-05-14 10:43    ┗[Koichi Shimamura <MA] Re: distinct でデータ欠落       
      9366 2004-05-14 10:57     ┣[seiji takegata <take]                               
->    9368 2004-05-14 11:29     ┗["HIROSE, Masaaki" <h]                               
      9371 2004-05-14 20:20      ┗[Koichi Shimamura <ma]