dtxa49711 2013-05-14 15:21
浏览 36
已采纳

MySQL内连接有两个表

I'm very new to MySQL and PHP and I'm struggling with inner joins between two tables. I'm constructing a script that reads an os commerce database and tells me which products is currently on back order. In order for the product to be on back order a value in the products_attributes table is set to '134', however it only reads the product_id and not the product_model which is in the 'products' table.

products_attributes(table name)
  options_values_id
  product_id

products(table name)
  product_id
  product_model

I want to select items that have the value of '134' in the products_attributes table then match the product_ids from both tables to get the product_model from the "products" table. I feel like the code is very easy but for some reason I'm struggling with how to construct the query and to display it.

  • 写回答

3条回答 默认 最新

  • dqvzfp6468 2013-05-14 15:28
    关注

    SELECT product_model FROM products as p,products_attributes as pa WHERE p.product_id = pa.product_id and pa.options_values_id = 134

    or

    SELECT p.product_model FROM products p INNER JOIN products_attributes as pa ON (p.product_id = pa.product_id) WHERE pa.options_values_id = 134

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化