Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two tables in Heidi SQL, t1 and t2. I am trying to select the first 15 rows from the two tables 2 columns, column1 (t1) and column2 (t2) when two conditions are met: id1 (t1) = id1 (t2) and id2 (t1) = id2 (t2).

I tried:

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

The selected rows do not follow the condition and I get the following error:

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"

Any ideas?

question from:https://stackoverflow.com/questions/66062714/heidisql-select-columns-from-two-tables-based-on-two-conditions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to move the WHERE clause between the FROM clause and the LIMIT clause:

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...