SQL 查询以显示 2 个不同表的行
SQL query to display rows of 2 different tables
我正在尝试弄清楚如何使用 OutageID = X
从两个不同的 table 中提取所有行。这样做的目的是在一个语句中查看当前中断和所有修订以查看所有更改。下面是我正在尝试的一个例子。但是,它将所有内容排成一行。我希望它像查询 SELECT * From Table WHERE X = Y
.
一样单独显示所有行
当前中断在一个 table 中,历史在另一个中,因此它们不会被覆盖,也不会更改当前数据库的设计。
中断 Table
`strSQL = "SELECT Outages.OutageID, Outages.Outage, Outages.Building,
Outages.OutageType, Outages.OutageStart, Outages.OutageStartTime,
Outages.OutageEnd, Outages.OutageEndTime, Outages.Duration,
Outages.Reason, Outages.Areas, Outages.Comment, Outages.ORN,
Outages.Contact, Outages.Phone, Outages.Job, Outages.Timestamp
FROM Outages
WHERE (((Outages.OutageID)=3305));"`
中断历史记录Table
`strSQL = "SELECT OutageHistory.RevisonID, OutageHistory.OutageID,
OutageHistory.Outage, OutageHistory.Building,
OutageHistory.OutageType,
OutageHistory.OutageStart, OutageHistory.OutageStartTime,
OutageHistory.OutageEnd, OutageHistory.OutageEndTime,
OutageHistory.Duration, OutageHistory.Reason, OutageHistory.Areas,
OutageHistory.Comment, OutageHistory.ORN, OutageHistory.Contact,
OutageHistory.Phone, OutageHistory.Job, OutageHistory.Timestamp
FROM OutageHistory
WHERE (((OutageHistory.OutageID)=3305));"`
`Private Sub All_Revision_Histoy_Click()
Dim strSQL As String
strSQL = "SELECT * From OutageHistory WHERE OutageHistory.OutageID = " &
Me.OutageID & ";"
Debug.Print strSQL
ShowDataSheet strSQL`
我认为我可能需要创建一个临时文件 table 并为结果插入两行,然后在关闭时删除 table。但是,我不确定该怎么做。我已经觉得我可能会被咬得比我能咀嚼的还要多。提前谢谢你。
select * from (
select 1 as revisionID, Outages.* FROM Outages
WHERE (((Outages.OutageID)=3305))
union
select OutageHistory.* FROM OutageHistory
WHERE (((OutageHistory.OutageID)=3305))
) order by revisionID desc
我正在尝试弄清楚如何使用 OutageID = X
从两个不同的 table 中提取所有行。这样做的目的是在一个语句中查看当前中断和所有修订以查看所有更改。下面是我正在尝试的一个例子。但是,它将所有内容排成一行。我希望它像查询 SELECT * From Table WHERE X = Y
.
当前中断在一个 table 中,历史在另一个中,因此它们不会被覆盖,也不会更改当前数据库的设计。
中断 Table
`strSQL = "SELECT Outages.OutageID, Outages.Outage, Outages.Building,
Outages.OutageType, Outages.OutageStart, Outages.OutageStartTime,
Outages.OutageEnd, Outages.OutageEndTime, Outages.Duration,
Outages.Reason, Outages.Areas, Outages.Comment, Outages.ORN,
Outages.Contact, Outages.Phone, Outages.Job, Outages.Timestamp
FROM Outages
WHERE (((Outages.OutageID)=3305));"`
中断历史记录Table
`strSQL = "SELECT OutageHistory.RevisonID, OutageHistory.OutageID,
OutageHistory.Outage, OutageHistory.Building,
OutageHistory.OutageType,
OutageHistory.OutageStart, OutageHistory.OutageStartTime,
OutageHistory.OutageEnd, OutageHistory.OutageEndTime,
OutageHistory.Duration, OutageHistory.Reason, OutageHistory.Areas,
OutageHistory.Comment, OutageHistory.ORN, OutageHistory.Contact,
OutageHistory.Phone, OutageHistory.Job, OutageHistory.Timestamp
FROM OutageHistory
WHERE (((OutageHistory.OutageID)=3305));"`
`Private Sub All_Revision_Histoy_Click()
Dim strSQL As String
strSQL = "SELECT * From OutageHistory WHERE OutageHistory.OutageID = " &
Me.OutageID & ";"
Debug.Print strSQL
ShowDataSheet strSQL`
我认为我可能需要创建一个临时文件 table 并为结果插入两行,然后在关闭时删除 table。但是,我不确定该怎么做。我已经觉得我可能会被咬得比我能咀嚼的还要多。提前谢谢你。
select * from (
select 1 as revisionID, Outages.* FROM Outages
WHERE (((Outages.OutageID)=3305))
union
select OutageHistory.* FROM OutageHistory
WHERE (((OutageHistory.OutageID)=3305))
) order by revisionID desc