アプリ版:「スタンプのみでお礼する」機能のリリースについて

MySQL3.23.58にて以下のSQLを実行したいのですが、
サブクエリーが利用できないため困っています。
やりたいことは、

1.memberテーブルにemailが重複したデータがあるため、
ユニークなemailを取得したい。
2.取得したemailを元にmemberテーブルを参照し、
シーケンシャルでユニークなidを取得したい。
3.その取得したidを元にflagが立っているものを取得したい。

以上になります。

実際に行いたいSQL文は以下になります。

select count(*) from member where id in (
select
max(id)
from
member
where
email in (
select
distinct email
from
M_MEMBER
where
email != '' and
email not like '%@docomo.ne.jp' and
email not like '%ezweb.ne.jp' and
email not like '%ido.ne.jp' and
email not like '%vodafone.ne.jp' and
email not like '%@jp-%'
)
) and flag = 1;

どうかよろしくお願いいたします。

A 回答 (3件)

たぶんこういうことだと思うのですが。


countは関係ないですよね?

select
email, max(id)
from M_MEMBER
where
email != '' and
email not like '%@docomo.ne.jp' and
email not like '%ezweb.ne.jp' and
email not like '%ido.ne.jp' and
email not like '%vodafone.ne.jp' and
email not like '%@jp-%'
and flag = 1
group by email;

この回答への補足

いえ、max(id)を元にflagが1の物をとりたいため、
ちょっと違ってきます。

補足日時:2005/11/17 23:44
    • good
    • 0

mysqlでサブクエリが正式対応になったのは


4.1以降だと記憶していますが・・・。
    • good
    • 0

うちも使えません。



mysql Ver 11.18 Distrib 3.23.52, for pc-linux-gnu (i686)

何故でしょうか?
バージョンが古くて対応していないか、オプションの設定が必要なのか、多分その何れかの気がします。

問い合わせのコードミスが原因では無い事を確認する為に同じ事をしてみて下さい。


mysql> create table tb1 (it1 varchar(5) );
Query OK, 0 rows affected (0.00 sec)

mysql> create table tb2 (it1 varchar(5) );
Query OK, 0 rows affected (0.00 sec)

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

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

mysql> select * from tb1;
+-------+
| it1 |
+-------+
| aaaaa |
+-------+
1 row in set (0.00 sec)

mysql> select * from tb2;
+-------+
| it1 |
+-------+
| aaaaa |
+-------+
1 row in set (0.00 sec)

mysql> select * from tb1 where tb1 in (select it1 from tb2);
ERROR 1064: You have an error in your SQL syntax near 'select it1 from tb2)' at line 1

mysql> select * from tb1 where tb1.it1 in (select tb2.it1 from tb2);
ERROR 1064: You have an error in your SQL syntax near 'select tb2.it1 from tb2)' at line 1

この回答への補足

#3さんのおっしゃる通り、Ver3ではサブクエリーに対応していないため、
当然の結果であると思います。

補足日時:2005/11/17 23:47
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!