基于两个条件的两个表中的 HeidiSQL Select 列

HeidiSQL Select columns from two tables based on two conditions

我在 Heidi SQL 有两张桌子,t1 和 t2。当满足两个条件时,我正在尝试 select 来自两个表的前 15 行 2 列,column1 (t1) 和 column2 (t2):id1 (t1) = id1 (t2) 和 id2 (t1) = id2 (t2).

我试过了:

SELECT a.column1, a.id1, a.id2, b.column2, b.id1, b.id2

FROM t1 a, t2 b LIMIT 15;

WHERE a.id1 = b.id1 AND a.id2 = b.id2

selected 行不符合条件,我收到以下错误:

Error: SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL Server version for the right syntax to use near "WHERE a.id1 = b.id1 AND a.id2 = b.id2"

有什么想法吗?

您必须将 WHERE 子句移动到 FROM 子句和 LIMIT 子句之间:

SELECT a.column1, a.id1, a.id2, b.column2, b.id1, b.id2
FROM t1 a, t2 b
WHERE a.id1 = b.id1 AND a.id2 = b.id2
LIMIT 15;