应该很简单? MySQL 查询:将一个 table 中的 ID (int) 替换为另一个 table 中的标题 (varchar)

Should be simple? MySQL query: substitute ID (int) in one table with title (varchar) from other table

我有一个问题,对我来说似乎很基本,但找不到答案。 我有两个 table:A 和 B。Table A 有一列带有 id-s (int),table B 将那些 id-s 与描述 (varchar .) 我想查询 table A,其中我将 id-s 替换为 table B 中的描述(one-one 关系)。 我目前有这个查询:

select tableA.* from tableA join tableB on (tableA.id=tableB.description);

这应该可以完成工作,除此之外我收到警告 1292:"Truncated incorrect DOUBLE value"。

明白什么意思了,两种数据类型不匹配。但是如何让它发挥作用呢?我确信这一定是一个简单的修复,而且我所要求的一直都在使用(例如,用书名替换 ISBN 等)...

如有任何帮助,我们将不胜感激!

根据要求编辑

对不起各位,我还以为不是模棱两可的……数据库结构:

mysql> describe tasks;
+----------+-----------------------+------+-----+---------+----------------+
| Field    | Type                  | Null | Key | Default | Extra          |
+----------+-----------------------+------+-----+---------+----------------+
| tid      | int(10) unsigned      | NO   | PRI | NULL    | auto_increment |
| pid      | int(10) unsigned      | YES  |     | NULL    |                |
| username | varchar(15)           | YES  |     | NULL    |                |
| task     | varchar(1000)         | NO   |     | NULL    |                |
+----------+-----------------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)

mysql> describe projects;
+-------+------------------+------+-----+---------+----------------+
| Field | Type             | Null | Key | Default | Extra          |
+-------+------------------+------+-----+---------+----------------+
| pid   | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| title | varchar(200)     | YES  |     | NULL    |                |
+-------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

我想要 "select * from tasks",其中每个 pid 都替换为同一查询中 table 个项目的相应标题。

希望现在更清楚了...

您可以简单地使用以下查询来连接两个 table 的内容,从任务 table 中获取所有条目,即使它们没有附加项目:

SELECT t.tid, t.username, t.task, p.title 
FROM tasks t 
LEFT JOIN projects p ON t.pid = p.pid;

如果您只想要带有附加项目的任务,请改用此查询:

SELECT t.tid, t.username, t.task, p.title 
FROM tasks t 
JOIN projects p ON t.pid = p.pid;