I have two tables Notification and 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.
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
Advertisement
Answer
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
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). UNION causes your result set to grow vertically (more rows)