I have two tables in SQL that I am trying to join.
Table1:
Date | Name | Shoe_Size | Pay_method
2020-04-04 05:27:00.0000000 | J.Bloggs | 8 | Credit
2020-04-04 05:55:00.0000000 | J.Smith | 10 | Cash
2018-06-20 05:27:00.0000000 | J.Bloggs | 6 | Cash
2018-08-15 05:55:00.0000000 | J.Smith | 9 | Cash
Table2:
Date_ID | Name | TShirt_Size
2020-04-04 00:00:00.0000000 | J.Bloggs | M
2020-04-04 00:00:00.0000000 | J.Smith | L
2018-06-20 00:00:00.0000000 | J.Bloggs | S
2018-08-15 00:00:00.0000000 | J.Smith | M
I would like to combine the tables to show:
Date | Name | Shoe_Size | TShirt_Size
2020-04-04 05:27:00.0000000 | J.Bloggs | 8 | M
2020-04-04 05:55:00.0000000 | J.Smith | 10 | L
2018-06-20 05:27:00.0000000 | J.Bloggs | 6 | S
2018-08-15 05:55:00.0000000 | J.Smith | 9 | M
Code I tried:
SELECT a.Date, a.Name, a.Shoe_Size, b.DATE_ID, b.Name, b.Tshirt_Size
From Table1 a, Table2.b
WHERE a.Name = b.Name
But obviously doesn't account for the date dimension.
Things I'm not sure how to get:
How to join based off two common columns (name & Date).
The date in Table1 has the exact time while the date in Table2 just has the right day. There will only be one entry per name per day.
Any help would be much appreciated.