top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How joiners will work without primary Key in MYSQL?

+1 vote
483 views

I am using for MySQL in ubuntu and created more then 7 tables. I haven't used the primary key in the tables.
Now my question is will joiner work without primary keys? If possible please share the query?

posted Mar 15, 2016 by Karthik Surya

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
Yes join operation works without the primary key, for example
SELECT *
FROM TableA A
INNER JOIN TableB B
ON A.col5 = B.col5;

Will you like to share more detail so that we can answer with more concrete...
Thank you

1 Answer

+1 vote

Yes, without primary key you can join the table but it will give some repeated records. So you need to check what you want -

For example: I have two tables
1. STUDENT (ID,NAME,SUBJECT)
2. TEACHER (ID,NAME,SUBJECT)

SELECT S.ID ST_ID,S.NAME ST_NAME FROM STUDENT S, TEACHER T
WHERE S.SUBJECT = T.SUBJECT(+)

This query will give you all record for which student have subject but there is no entry in teacher table.

answer Mar 15, 2016 by Manoj Goswami
...