search

Home  >  Q&A  >  body text

SQL Inner Join Performance Data Duplication

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.

P粉253518620P粉253518620266 days ago496

reply all(1)I'll reply

  • P粉022501495

    P粉0225014952024-03-31 00:16:58

    filter

    qt.qstnId = 1 is a filter clause; it belongs to the WHERE clause.

    relation

    qt.qstnId = Question.qid Describes how tables are related through JOIN. It belongs to the ON clause after JOIN.

    Fix your query; if you still have concerns; provide SHOW CREATE TABLE so we can see if you have the necessary indexes (for performance).

    reply
    0
  • Cancelreply