how can id assign foreign key mysqli

2019-09-21 10:34发布

I have created at 2 tables. These tables are Department, employee.

Now i want to assign foreign key in department table and join with employee table.

have any idea??

SELECT id,department FROM department; 
SELECT * FROM `employee'

2条回答
孤傲高冷的网名
2楼-- · 2019-09-21 11:05

Are you looking for this:-

$query="select emp.name, dep.department from employee emp 
INNER JOIN 
department dep ON 
emp.department=dep.department 
order by emp.name asc";
查看更多
Emotional °昔
3楼-- · 2019-09-21 11:31
create employee table field are- id(primary key),name,dept_id
department table fields are-dept_id(primary key),name

after select the dept_id.give index. enter image description here

than select the department table and dept_id.than click save button. enter image description here

查看更多
登录 后发表回答