The Natural Join of Mysql -
i'm little confused natural join in mysql.
suppose that: there 2 tables
table1
has columns: id, name, address, number (id pk of table1)
table2
has columns: id, name, number, money (id pk of table2)
i have make "id"
of table1
foreign key, referencing "id"
of table2
and suppose "number"
in table1
"people's number"
, "number"
in table2
"telephone number"
2 columns have different meaning same name
when natural join of table1
, table2
:
does mysql check columns of table1
, table2
, name same, means tuple(row) selected ,if , if, "id"
, "name"
, "number
" must same (for example, "id"
, "name"
same "number"
different, row not selected)?
or
does mysql check foreign keys created, means row selected , if , if, "id"
same?
another question is:
after natural join of table1
, table2
, there 1 column called "id"
or 2 columns called "table1.id"
, "table2.id"
??
thanks indeed!
you shouldn't use natural join that, need use left join. table1 parent table? @ least sounds should be, foreign key reference should parent table inserted child table. parent table has 1 entry per reference id , child table may have many, one, or no entries referenced id
select table1.id, table1.number person_number, table2.number phone_number table1 left join table2 on table1.id = table2.id
Comments
Post a Comment