合并一个数据库中的两个表

时间:2021-12-12 12:32:34

I've made this employee information system where employees can give their own feedbacks. Here's what it looks like:

我建立了这个员工信息系统,员工可以在其中提供自己的反馈。这是它的样子:

EIS

When you click the "Employee Feedbacks" button it would redirect you to this page:

当您单击“员工反馈”按钮时,它会将您重定向到此页面:

Employee Feedback Form

员工反馈表

Now I have 2 tables in my database, the employee and tbl_feedback:

现在我的数据库中有2个表,即employee和tbl_feedback:

DB tables

The problem is with the different ID's. How do I merge the two?

问题在于ID不同。我如何合并这两个?

For the employee table:

对于员工表:

employee table

For the tbl_feedback:

对于tbl_feedback:

tbl_feedback

What I want to happen is for the full name to automatically show up when the user clicks on "Employee Feedback". I think that would only be possible if I merge the two tables.

我想要发生的是当用户点击“员工反馈”时自动显示全名。我认为只有合并这两个表才有可能。

I don't know what source code you guys need but just tell me and I will provide. Thank you so much!

我不知道你们需要什么源代码,但只是告诉我,我会提供。非常感谢!

1 个解决方案

#1


0  

Do, please, have a look at the good advice from @Pete because that will help us to help you.

请看看@Pete的好建议,因为这有助于我们为您提供帮助。

Here is just a hint about how you use primary and foreign keys to link your tables:

这里只是一个关于如何使用主键和外键来链接表的提示:

create table employee
(
    id         integer,
    fullname   varchar(64),
    username   varchar(32),
    email      varchar(128),
    address    varchar(512),
    contact    varchar(16),
    gender     varchar(16),
    password   varchar(32),
    constraint primary_key_employee primary key (id)
);


create table feedback
(
    id           integer,
    employee_id  integer,
    website      varchar(128),
    message      varchar(2048),
    constraint primary_key_feedback primary key (id),
    constraint foreign_key_feedback_employee foreign key (employee_id) references employee (id)
);

select 
    a.fullname,
    a.email,
    b.website,
    b.message
from
    employee a
    join 
    feedback b
    on a.id = b.employee_id;

There are various things that you could improve in you tables (no clear passwords, for example). That's not intended to be mean, you're clearly making a start, and thinking about what you need, and that's good. I would suggest that you invest a little time in understanding how SQL databases work. There is a free resource at https://www.w3schools.com/sql/default.asp. I have tried to offer practical explanations that you can find here, and there are many other resources.

您可以在表格中改进各种内容(例如,没有明确的密码)。这并不意味着,你显然是一个开始,并思考你需要什么,这是好的。我建议您花一点时间来了解SQL数据库的工作原理。 https://www.w3schools.com/sql/default.asp上有免费资源。我试图提供您可以在这里找到的实用解释,还有许多其他资源。

I hope it goes well for you.

我希望它适合你。

#1


0  

Do, please, have a look at the good advice from @Pete because that will help us to help you.

请看看@Pete的好建议,因为这有助于我们为您提供帮助。

Here is just a hint about how you use primary and foreign keys to link your tables:

这里只是一个关于如何使用主键和外键来链接表的提示:

create table employee
(
    id         integer,
    fullname   varchar(64),
    username   varchar(32),
    email      varchar(128),
    address    varchar(512),
    contact    varchar(16),
    gender     varchar(16),
    password   varchar(32),
    constraint primary_key_employee primary key (id)
);


create table feedback
(
    id           integer,
    employee_id  integer,
    website      varchar(128),
    message      varchar(2048),
    constraint primary_key_feedback primary key (id),
    constraint foreign_key_feedback_employee foreign key (employee_id) references employee (id)
);

select 
    a.fullname,
    a.email,
    b.website,
    b.message
from
    employee a
    join 
    feedback b
    on a.id = b.employee_id;

There are various things that you could improve in you tables (no clear passwords, for example). That's not intended to be mean, you're clearly making a start, and thinking about what you need, and that's good. I would suggest that you invest a little time in understanding how SQL databases work. There is a free resource at https://www.w3schools.com/sql/default.asp. I have tried to offer practical explanations that you can find here, and there are many other resources.

您可以在表格中改进各种内容(例如,没有明确的密码)。这并不意味着,你显然是一个开始,并思考你需要什么,这是好的。我建议您花一点时间来了解SQL数据库的工作原理。 https://www.w3schools.com/sql/default.asp上有免费资源。我试图提供您可以在这里找到的实用解释,还有许多其他资源。

I hope it goes well for you.

我希望它适合你。