douwei2966 2015-08-29 01:08
浏览 91

使用MySQL查询显示品牌

I have 3 MySQL tables:

  • produs(id, name, price)
  • spec_laptop(id,id_produs -foreigkey(produs-id), brand)
  • spec_telefon(id,id_produs -foreigkey(produs-id), brand)

and 2 pages:

  • telefon.php (which will have a list of brands of cellphones)
  • laptop.php (which will have a list of brands of laptops)

    I tried to make a query which displays names and prices from produs which:

    1. When I click a brand from telefon.php , display all cellphones names and prices who have that brand
    2. When I click a brand from laptop.php , display all laptops names and prices who have that brand

Example: (it doesn't work and I don't know why):

SELECT t1.*,t2.*,t3.* FROM produs as t1 join spec_laptop as t2  join spec_telefon as t3 WHERE(t1.id=t3.id_produs OR t1.id=t2.id_produs) AND t2.brand='Acer'
  • 写回答

1条回答 默认 最新

  • doumu9799 2015-08-29 01:17
    关注

    You joined them the wrong way, try this one :

    SELECT * FROM produs as t1
    inner join spec_laptop as t2 ON t2.id_produs = t1.id
    inner join spec_telefon as t3 ON t3.id_produs = t1.id
    WHERE t2.brand='Acer'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分