[英]How to join values from one column to another
I have two tables Notification and Worker Notifications. 我有两个表Notification和Worker Notifications。 On those tables there are two similar columns called Time.
在这些表上有两个类似的列,称为时间。 My worker class inherits Notification and I would like to join all preexisting times on worker with notification time.
我的工作人员类继承了Notification,我想将所有先前存在的工作时间与通知时间一起加入。
id | Worker| Time
-------------
10 | John| 8/17/2019
20 | Rui| 8/17/2019
30 | Pen| 8/17/2019
id | Notification| Time |WorkerID
-----------------------------------
10 | John| 8/17/2019 | 10
20 | Rui| 8/17/2019 |20
30 | Pen| 8/17/2019 |30
SELECT category_id, col1, col2, col3 FROM items_a UNION SELECT category_id, col1, col2, col3 FROM items_b 从items_a中选择category_id,col1,col2,col3从项目_b中选择category_id,col1,col2,col3
I dare say it should actually be 我敢说实际上应该是
SELECT *
FROM
worker w
INNER JOIN
notifications n
ON
w.id = n.workerid
I say this because a notification has a workerid so it clearly "belongs to a worker" - it isn't necessarily related to a worker based on the time, as if two times are the same then you could end up joining a notification assigned to John, to Dave intead 我之所以这样说,是因为通知中有一个workerid,所以它显然“属于某个工作人员”-不一定基于时间与该工作人员相关,就好像两次相同,那么您最终可能会加入分配给约翰,戴夫·英特
But if you insist on joining on the time the pattern is the same: 但是,如果您坚持加入时间,则模式是相同的:
SELECT *
FROM
worker w
INNER JOIN
notifications n
ON
w.time = n.time
JOIN causes your result set to grow sideways (more columns). JOIN使您的结果集横向增长(更多列)。 UNION causes your result set to grow vertically (more rows)
UNION导致结果集垂直增长(更多行)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.