简体   繁体   English

两个表中的主键与另一个表PHP的关系

[英]the relationship of the primary keys in the two tables to another table PHP

my tables 我的桌子

A_ID   NAME
1     apple
2     banana
3     watermelon
4     kiwi
5     peace

B_ID   NAME 
1     green
2     red
3     blue
4     yellow

relationship table; 关系表;

A_ID | B_ID
1      2
1      3
2      4
3      1

I want to print at Php; 我想在Php打印;

  • apple-red 苹果红
  • apple-blue 苹果蓝

使用联接查询就可以做到。

SELECT A.name, B.name FROM A JOIN AB ON A.id=AB.A_id JOIN B ON B.id=AB.B_id

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kohana 2.3建立在两个表之间具有一种关系,且主表未命名为“ id” - Kohana 2.3 establish has one relationship between two tables with primary keys not named as “id” mysql表有两个来自另一个表的外键 - mysql tables have two foreign keys from another same table PHP/MYSQL/Keys:将表一致地插入到两个表中 - PHP/MYSQL/Keys: Inserting Table into Two Tables Consistently Yii has_many与两个primary_keys的关系 - Yii has_many relationship with two primary_keys 从php中的表的两个主键生成唯一的12个字母的字母数字字符串 - Generate unique 12 letter alphanumeric string from two primary keys of table in php 具有两个外键的两个表之间的Laravel关系 - Laravel relationship between two tables with two foreign keys 如何从两个表中查询匹配表中的外键和另一个表中的主键 - How do I query from two tables matching the foreign key from table with the primary key from another PHP将值插入两个表并将这些表的键插入链接表 - PHP Insert values into two tables and insert keys from those tables into link table PHP / SQL连接四个表,其中两个表依赖另一个 - PHP/SQL Join four tables where two table rely on another 具有两个不同表的单表关系 - Single table relationship with two different tables
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM