For those SQL guru's out there - I was wondering if/how I can be more efficient with my SQL statements. I have the following four Access tables.
tblBuildings
Bldgid - Primary Key
BldgDesc - description of building
tblRoomMaster
RoomID - Primary Key
BldgID - Foreign key (tblBuildings)
RoomUse - Foreign Key (tblRoomUse)
SqFt - Square Footage of Room
tblRoomUse
RoomUse - Primary Key
Assignable - Yes/No
tblFloors
FloorId - Primary Key
BldgID - Foreign key (tblBuildings)
SqFt - Square Footage of Floor
I need a query that displays 'For Each Building' the total square footage of all the rooms where Assignable = Yes; and the total Square Footage of all the Floors for that particualr Building.
BuildingID - Assignable Sq Ft - Total Floor Sq Ft.
Can I accomplish this with a single SELECT statement? Or use nested queries? Or another method?
I can create 2 queries each Grouped by tblBuildins.bldgid to get the results I want.
Assignable Sq Ft:
SELECT tblBuildings.BldgID, sum(qryRoomMaster.SqFt) as ASF
FROM (tblBuildings INNER JOIN qryRoomMaster ON tblBuildings.BldgID = qryRoomMaster.Bldgid) INNER JOIN tblRoomUse ON qryRoomMaster.RoomUse = tblRoomUse.RoomUse
WHERE (((tblRoomUse.Assignable)=-1))
Group by tblBuildings.BldgID;
Floor Sq FT:
SELECT tblBuildings.BldgID, sum(tblFloors.SqFt) as FloorSqFt
FROM tblBuildings INNER JOIN tblFloors ON tblBuildings.BldgID = tblFloors.BldgID
Group by tblBuildings.BldgID;
...but I was wondering if I could do it one step.
Thanks for your time,
SDF
tblBuildings
Bldgid - Primary Key
BldgDesc - description of building
tblRoomMaster
RoomID - Primary Key
BldgID - Foreign key (tblBuildings)
RoomUse - Foreign Key (tblRoomUse)
SqFt - Square Footage of Room
tblRoomUse
RoomUse - Primary Key
Assignable - Yes/No
tblFloors
FloorId - Primary Key
BldgID - Foreign key (tblBuildings)
SqFt - Square Footage of Floor
I need a query that displays 'For Each Building' the total square footage of all the rooms where Assignable = Yes; and the total Square Footage of all the Floors for that particualr Building.
BuildingID - Assignable Sq Ft - Total Floor Sq Ft.
Can I accomplish this with a single SELECT statement? Or use nested queries? Or another method?
I can create 2 queries each Grouped by tblBuildins.bldgid to get the results I want.
Assignable Sq Ft:
SELECT tblBuildings.BldgID, sum(qryRoomMaster.SqFt) as ASF
FROM (tblBuildings INNER JOIN qryRoomMaster ON tblBuildings.BldgID = qryRoomMaster.Bldgid) INNER JOIN tblRoomUse ON qryRoomMaster.RoomUse = tblRoomUse.RoomUse
WHERE (((tblRoomUse.Assignable)=-1))
Group by tblBuildings.BldgID;
Floor Sq FT:
SELECT tblBuildings.BldgID, sum(tblFloors.SqFt) as FloorSqFt
FROM tblBuildings INNER JOIN tblFloors ON tblBuildings.BldgID = tblFloors.BldgID
Group by tblBuildings.BldgID;
...but I was wondering if I could do it one step.
Thanks for your time,
SDF