I have 2 tables:
Citizen_Location
where it has Name and Location:
Citizens
where it contains Name, Age & Exp:
So, I've performed join
operation in it:
select c.name,cl.location
from citizens as c
join citizen_location as cl;
Output:
***564 row(s)*** returned 0.000 sec / 0.000 sec
Whenever I hit the execute button, that rows gets increased by 1 by default. Also, even executing normal query, output always shown twice and as your keep hitting execute button, it keeps increasing!
I tried to open new query tab and reinstalled the program but the problem remains the same. Everytime same output shown twice and thrice and so on.
JOIN
is short for INNER JOIN
in SQL. It must be followed by a join condition which is either an ON
clause or a USING
clause. You have neither, so MySQL should raise a syntax error here. It can be considered a flaw in the DBMS that it doesn't.
Obviously, MySQL turns your JOIN
into a CROSS JOIN
instead, ie an inconditional join. Thus you join every row of the left table with every row of the right table.
The solution to your problem is simple: Just add a condition.
select c.name, cl.location
from citizens as c
join citizen_location as cl on cl.name = c.name;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.