Question : How do I combine these tables in SQL?

I have a question.
How would I combine these three tables into one table with DriverID, DriverStatus, LocationDescription, and BoardMapping?


-- DriverStatus
Select l1.DriverID,DriverStatus, LocationDescription, BoardType FROM
(
SELECT DriverID, DriverStatus FROM
(
SELECT l1.DriverID, l1.StatusDate, DriverStatusMapping.DriverStatusID  FROM
(
SELECT DriverID, MAX(StatusDate) AS StatusDate  from DriverStatusMapping
GROUP BY DriverID
) l1,
DriverStatusMapping

WHERE l1.DriverID=DriverStatusMapping.DriverID
AND l1.StatusDate = DriverStatusMapping.StatusDate
) l2,
DriverStatus
Where l2.DriverStatusID = DriverStatus.DriverStatusID

--Location Mapping
SELECT DriverID, LocationDescription FROM
(
SELECT l1.DriverID, l1.StatusDate, LocationMapping.LocationID  FROM
(
SELECT DriverID, MAX(StatusDate) AS StatusDate  from LocationMapping
GROUP BY DriverID
) l1,
LocationMapping

WHERE l1.DriverID=LocationMapping.DriverID
AND l1.StatusDate = LocationMapping.StatusDate
) l2,
Location
Where l2.LocationID = Location.LocationID
--Board Mapping

SELECT DriverID, BoardType FROM
(
SELECT l1.DriverID, l1.StatusDate, BoardTypeID FROM
(
SELECT DriverID, MAX(StatusDate) AS StatusDate FROM BoardMapping Group by DriverID
) l1,
BoardMapping
WHERE l1.DriverID = BoardMapping.DriverID
AND l1.StatusDate = BoardMapping.StatusDate
) l2,
Board
WHERE l2.BoardTypeID = board.BoardTypeID

Answer : How do I combine these tables in SQL?

Try this query
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
Select x.DriverID,DriverStatus, LocationDescription, BoardType 
FROM
(
SELECT DriverID, DriverStatus FROM
(
SELECT l1.DriverID, l1.StatusDate, DriverStatusMapping.DriverStatusID  FROM
(
SELECT DriverID, MAX(StatusDate) AS StatusDate  from DriverStatusMapping
GROUP BY DriverID
) l1,
DriverStatusMapping

WHERE l1.DriverID=DriverStatusMapping.DriverID
AND l1.StatusDate = DriverStatusMapping.StatusDate
) l2,
DriverStatus
Where l2.DriverStatusID = DriverStatus.DriverStatusID
) x
INNER JOIN (
--Location Mapping
SELECT DriverID, LocationDescription FROM
(
SELECT l1.DriverID, l1.StatusDate, LocationMapping.LocationID  FROM
(
SELECT DriverID, MAX(StatusDate) AS StatusDate  from LocationMapping
GROUP BY DriverID
) l1,
LocationMapping

WHERE l1.DriverID=LocationMapping.DriverID
AND l1.StatusDate = LocationMapping.StatusDate
) l2,
Location
Where l2.LocationID = Location.LocationID
) y ON x.DriverId = y.DriverId
--Board Mapping
INNER JOIN (
SELECT DriverID, BoardType FROM 
(
SELECT l1.DriverID, l1.StatusDate, BoardTypeID FROM 
(
SELECT DriverID, MAX(StatusDate) AS StatusDate FROM BoardMapping Group by DriverID
) l1,
BoardMapping
WHERE l1.DriverID = BoardMapping.DriverID 
AND l1.StatusDate = BoardMapping.StatusDate
) l2,
Board
WHERE l2.BoardTypeID = board.BoardTypeID
) z ON x.DriverId = z.DriverId
Random Solutions  
 
programming4us programming4us