[PHP-users 29859] サブクエリが使えない場合の方法

uto.hideo uto.hideo @ jp.fujitsu.com
2006年 7月 24日 (月) 12:16:36 JST


お世話になります。

MYSQL(Ver3.23)ではサブクエリが使えないと思うのですが、
SELECT文の入れ子を行う場合、みなさんどうされていますか?

例えば、下記CREATE 文の結果を、下のSELECT文で使いたいのですが

mysql_select_db($database, $user);

CREATE TEMPORARY TABLE ct1 AS
SELECT t1.pid, t1.plant, t2.gid, t2.group, t2.theme_cd, t2.theme, t3.hid,
t3.h_kubun, t3.h_name, t4.kid, t4.k_kubun, t2.theme_etc
FROM t1, t2, t3, t4
ORDER BY t1.pid, t2.theme_cd, t3.hid, t4.kid;

$query_Rs3 = "SELECT ct1.gid, ct1.group, ct1.theme_cd, ct1.theme,
ct1.theme_etc, t5.plant,
t5.t_name, ct1.h_name, ct1.h_kubun
FROM ct1 INNER JOIN t5 ON ct1.theme = t5.stheme
GROUP BY ct1.gid, ct1.group, ct1.theme_cd, ct1.theme, ct1.theme_etc,
t5.plant, t5.t_name, ct1.h_name, ct1.h_kubun
ORDER BY ct1.theme_cd, t5.t_name, ct1.h_name";

$Rs3 = mysql_query($query_Rs3, $user) or die(mysql_error());
$row_Rs3 = mysql_fetch_assoc($Rs3);

<body>配下は、do...whileループで$row_Rs3の各フィールドを表示

でやってみましたが、どうもうまく行きません。
一時的に CREATE TEMPORARY TABLE ** AS を使って
SELECT文の入れ子を行う方法で試してみたのですが、
phpではどの様に書くのでしょうか?

どなたかご教授頂けませんでしょうか?
よろしくお願い致します。

宇都



PHP-users メーリングリストの案内