dongquxiao8545 2011-07-21 23:29
浏览 8

遗漏了什么? [关闭]

I have three tables

product_color
===
color_id (primary)
color_initial
red
green
blue

school_art
===
id(primary)
art_loc
series_code

set_color
===
setcolors_id
school_art_id
color_id 

What I would like to do is:

Get the red, green and blue from product_color table where the product_color.color_id = set_color.color_id AND WHERE the set_color.school_art_id = school_art.id

This is what I have, but being that it is not working, clearly I am missing something. Any help would SOOO gratefully appreciated.

$colors =
"SELECT * FROM
    product_color
JOIN
    set_colors
ON
    product_color.color_id = set_colors.color_id
WHERE
    set_colors.school_art_id = '{$school_art_id}'";

$colorresult = mysql_query($colors) or die(mysql_error());
$returncolors = mysql_fetch_array($colorresult);
  • 写回答

2条回答 默认 最新

  • dousong5492 2011-07-21 23:55
    关注

    I'm assuming that since you say school_art.id you also want to pull in the school_art table. For that, you have to JOIN all three tables:

    SELECT * FROM product_color
             JOIN set_color ON(product_color.color_id = set_color.color_id)
             JOIN school_art ON(school_art.id = set_color.school_art_id);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败