[英]select columns from another table and create a column
I have 2 tables 我有2张桌子
ads: 广告:
+------------+------------+-------------+
| id | width | height |
+------------+------------+-------------+
| 1 | 300 | 250 |
| 2 | 550 | 50 |
| 3 | 300 | 250 |
| 4 | 300 | 250 |
| 5 | 550 | 50 |
+------------+------------+-------------+
assigned_ads: Assigned_ads:
+------------+------------+-------------+
| id | location | ad_id |
+------------+------------+-------------+
| 1 | hp1 | 2 |
| 2 | hp2 | 3 |
| 3 | hp3 | 5 |
| 4 | hp4 | 1 |
| 5 | hp5 | 4 |
+------------+------------+-------------+
I have ad_id
as a foreign key... 我有
ad_id
作为外键...
With PHP I will be need to output the size of the ad from ad_id
but this information is held in the ads
table. 使用PHP时,我需要从
ad_id
输出广告的大小,但是此信息保存在ads
表中。 The information I will need is width x height
. 我需要的信息是
width x height
。 I know there's a query I can use to create an additional column with this information but for the life of me I can't remember, or find it. 我知道有一个查询可以用来创建包含此信息的其他列,但是我一生都无法记住或找到它。
Any help appreciated. 任何帮助表示赞赏。
SELECT a.width, a.height
FROM assigned_ads aa
INNER JOIN ads a
ON aa.ad_id = a.id
WHERE aa.id = 123 -- Your value goes here.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.