SQL Inner Join Performance Data Duplication
P粉253518620
P粉253518620 2024-03-30 09:17:19
0
1
462

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粉253518620
P粉253518620

reply all(1)
P粉022501495

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).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template