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 = 1is a filter clause; it belongs to theWHEREclause.relation
qt.qstnId = Question.qidDescribes how tables are related throughJOIN. It belongs to theONclause afterJOIN.Fix your query; if you still have concerns; provide
SHOW CREATE TABLEso we can see if you have the necessary indexes (for performance).