[英]Check a record exists in mysql
Assume I have following three tables.假设我有以下三个表。
Staff
id | name
---------
1 Tom
2 Mary
Fulltime staff
id | name
---------
1 Tom
Parttime staff
id | name
---------
2 Mary
Is there a way I can display like this using SQL?有没有办法可以使用 SQL 显示这样的内容? Or should I add one more column in the Staff table?或者我应该在 Staff 表中再添加一列吗?
Mysql
id | name | Work nature
----------------------
1 Tom Fulltime
2 Mary Parttime
Unless you want people to have different names when they're full time vs part time, do not repeat people's names.除非您希望人们在全职和兼职时使用不同的名字,否则不要重复人们的名字。
There's nothing preventing someone from being both full and part time.没有什么可以阻止一个人既是全职又是兼职。 Or neither.或者两者都不是。 Instead of three tables, have one.有一张桌子,而不是三张桌子。
create table staff (
id bigint primary key auto_increment,
name varchar(255) not null,
type enum('fulltime', 'parttime') not null
)
Now each person can only be one type of employee, the names are not repeated, and your select is trivial.现在每个人只能是一种员工,名字不重复,你的选择是微不足道的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.