Table -- > qt
qstnId | tagID |
---|---|
1 | 1 |
1 | 2 |
2 | 3 |
2 | 4 |
2 | 2 |
Table-->Question
qid |
---|
1 |
2 |
qid is the primary key, qstnId is Fk
Now when I run the query -->
mysql> select tagId from qt inner join question on qt.qstnId = 1;
It’s back;
tagID |
---|
2 |
1 |
2 |
1 |
My question is why am I getting duplicate data here.
filter
qt.qstnId = 1
is a filter clause; it belongs to theWHERE
clause.relation
qt.qstnId = Question.qid
Describes how tables are related throughJOIN
. It belongs to theON
clause afterJOIN
.Fix your query; if you still have concerns; provide
SHOW CREATE TABLE
so we can see if you have the necessary indexes (for performance).