0

我有两个表:producturl_alias

产品表有两列:product_idmodel

url_alias表有两列:product_idkeyword

因此,product_id 是两个表的唯一主键

现在,如果两个表的product_id相同,我想将product.model的信息添加(附加)到url_alias.keyword 。

例如:

product.product_id = 123
product.model = 987

product.product_id = 123
url_alias.keyword = my-first-book.html

Desired result = 987-my-first-book.html

我该怎么做?

PS:'-'连字符也需要与模型添加。

4

3 回答 3

0

试试CONCAT::

Select
product.product_id,
CONCAT(product.model,'-', url_alias.keyword)
from 
product 
inner join url_alias on (url_alias.product_id=product.product_id)
于 2013-10-17T07:33:42.390 回答
0
SELECT CONCAT(product.model, '-', url_alias.keyword) AS url
FROM product
INNER JOIN url_alias
ON product.product_id = url_alias.product_id
WHERE product.product_id = '123'
于 2013-10-17T07:34:27.133 回答
0
    SELECT CONCAT(p.product_id,' - ',u.keyword ) AS res
    FROM product AS p
    LEFT JOIN
    url_alias AS u USING (product_id)
    WHERE p.product_id = 123

注意:如果您想获得所有产品的结果,请删除 WHERE 条件

于 2013-10-17T07:35:39.750 回答