select columns from another table and create a column
I have 2 tables
ads:
+------------+------------+-------------+
| id | width | height |
+------------+------------+-------------+
| 1 | 300 | 250 |
| 2 | 550 | 50 |
| 3 | 300 | 250 |
| 4 | 300 | 250 |
| 5 | 550 | 50 |
+------------+------------+-------------+
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...
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. The infor开发者_运维技巧mation I will need is 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.
精彩评论