mySQL JOIN来自不同的TABLE不同的RECORD

时间:2022-09-28 00:50:36

I'm trying to join two tables, but inputs are not the same.

我正在尝试加入两个表,但输入不一样。

On table Category category_id is an integer.

在表类别category_id是一个整数。

But on table url_alias category is a string like category_id=15.

但是在表url_alias类别是一个类似category_id = 15的字符串。

I've tried:

SELECT * FROM category c
LEFT JOIN url_alias ua ON ( ua.category = 'category_id=c.category_id')

No luck. How can I reach that table?

没运气。我怎样才能到达那张桌子?

1 个解决方案

#1


You have placed c.catagory_id inside the quotes ('), thus making it part of the string literal. Instead, you should concat its value to category_id= literal:

您已将c.catagory_id放在引号(')中,从而使其成为字符串文字的一部分。相反,您应该将其值连接到category_id = literal:

SELECT    * 
FROM      category c
LEFT JOIN url_alias ua ON ua.category = CONCAT('category_id=', c.category_id)

#1


You have placed c.catagory_id inside the quotes ('), thus making it part of the string literal. Instead, you should concat its value to category_id= literal:

您已将c.catagory_id放在引号(')中,从而使其成为字符串文字的一部分。相反,您应该将其值连接到category_id = literal:

SELECT    * 
FROM      category c
LEFT JOIN url_alias ua ON ua.category = CONCAT('category_id=', c.category_id)