在SQL搜索多个table的问题~~~大家帮忙看看

huokongfly 2009-12-17 01:45:05
有个应用需要返回多个table,
$query1 = "SELECT ProductID FROM Accessories,CPU,Drive,GraphicCard,HardDisk,Memory,Monitor,Motherboard,Other";
$results1 = mysql_query($query1, $connect)or die("Query database failed 3");

while ($row1 = mysql_fetch_row($results1))




可是总说Query database failed
每个table里都有ProductID,如果把ProductID换成count(*)就没问题,
实在找不出哪有毛病,高手帮忙看看~~~~~~~
...全文
96 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
huokongfly 2009-12-17
  • 打赏
  • 举报
回复
很详细~~谢谢大家~~
阿_布 2009-12-17
  • 打赏
  • 举报
回复

mysql> select * from cpu;
+-----------+
| productid |
+-----------+
| 1 |
| 2 |
| 3 |
| 4 |
+-----------+
4 rows in set (0.00 sec)

mysql> select * from drive;
+-----------+
| productid |
+-----------+
| 1 |
| 2 |
| 3 |
+-----------+
3 rows in set (0.00 sec)

mysql> select concat(group_concat(distinct cpu.productid),',',
-> group_concat(distinct drive.productid)) productids
-> from cpu,drive;
+---------------+
| productids |
+---------------+
| 1,2,3,4,1,2,3 |
+---------------+
1 row in set (0.00 sec)
t240034137 2009-12-17
  • 打赏
  • 举报
回复

SELECT ProductID FROM Accessories,CPU。。。

SELECT 表中的字段 FROM表
你表中字段不明确
huokongfly 2009-12-17
  • 打赏
  • 举报
回复
是说用Accessories.ProductID, CPU.ProductID 。。。的方法吗?
有没有办法让他们结合在一起输出,就是只输出一行, 都是ProductID ?
阿_布 2009-12-17
  • 打赏
  • 举报
回复
多个表里面有相同的字段名,要指定表名。

21,891

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧