【发布时间】:2011-01-21 22:55:24
【问题描述】:
MySQL
表1:
+--------+------+
| listid | type |
+--------+------+
| 1 | a |
+--------+------+
| 2 | a |
+--------+------+
| 3 | b |
+--------+------+
表2:
+----+--------+------+
| id | listid | code |
+----+--------+------+
| 1 | 1 | ax |
+----+--------+------+
| 2 | 1 | bx |
+----+--------+------+
| 3 | 2 | ax |
+----+--------+------+
| 4 | 2 | bx |
+----+--------+------+
| 5 | 2 | cx |
+----+--------+------+
| 6 | 3 | ax |
+----+--------+------+
| 7 | 3 | bx |
+----+--------+------+
任务
在一个查询中,我想检查是否:
1) 在 table2 表中,只有 "ax" 和 "bx" 被列为 code
2) 我在 1) 中得到的 listid 的类型是表 table1
中的“a”PHP
$a = mysql_query("SELECT t1.listid FROM table1 AS t1, table2 AS t2......");
$b = mysql_fetch_assoc($a);
if($b['listid'])
{
echo $b['listid'];
}
else
{
echo 'nothing found';
}
输出
listid = 1
listid = 2 为假,因为 table2
中也包含“cx”listid = 3 为假,因为它在 table1
中有类型“b”我希望这是有道理的:)
【问题讨论】: