I am seeing people using two different method in SQL to join the table; for example, I have two tables:
Table A Table B
DeliveryDate EMP Hours Date EMP Route
5/14/2017 611300 1 5/14/2017 611300 11101
5/14/2017 611301 3 5/14/2017 611301 11102
5/13/2017 611300 4 5/13/2017 611300 11101
5/13/2017 611301 5 5/13/2017 611301 11102
5/13/2017 611301 11103
for those two tables, EMP(employee id) is string, hours is number, basically want to join tow table together in order to get hour many hours employee worked ans how many routes he worked. I saw people are using two different code to achieve the purpose, but what the real difference between those two methods? which one is better? code below:
Code 1:
SELECT C.DELIVERYDATE,C.EMP,C.HOURS,D.ROUTES
FROM
(
SELECT
A.DeliveryDate, A.EMP, A.Hours
FROM
A
) C,
(
SELECT
B.DATE,B.EMP,COUNT(B.ROUTE) AS ROUTES
FROM
B
group BY B.DATE,B.EMP
)D
WHERE C.DeliveryDate=D.DATE
AND C.EMP=D.EMP
Code 2:
SELECT C.DELIVERYDATE,C.EMP,C.HOURS,D.ROUTES
FROM
(
SELECT
A.DeliveryDate&A.EMP AS DATEEMP, A.DELIVERYDATE,A.EMP,A.Hours
FROM
A
) C,
(
SELECT
B.DATE&B.EMP AS DATEEMP,B.DATE,B.EMP,COUNT(B.ROUTE) AS ROUTES
FROM
B
group BY B.DATE,B.EMP
)D
WHERE C.DATEEMP=D.DATEEMP
Thanks so much