I have two "main" EAVs that INNER JOIN with common value tables. I query them separately and use UNION to join the two recordsets. However, this produces duplicates and theoretically reduces performance because of repetative table loads. I'd like to merge the two queries into one but am having difficultly with the logic.
These tables have 100,000s of rows
Audits_Assets:
pk | Host | Entity | Attrib | Value | TimeStamp
-----------------------------------------------
1 1 2 3 1 1
...
Audits_Logons:
pk | Host | Entity | Attrib | Value | TimeStamp
-----------------------------------------------
1 1 4 5 6 2
...
Audits_Values:
pk | Value
---------------
1 b-136615
2 Computer
3 HostName
4 Logon
5 CurrentUser
6 Geates
...
Audits_TimeStamps:
pk | Value
---------------
1 2/15/2011 3:16:00 PM
2 2/16/2011 9:30:00 AM
...
Based on this extremely crude representation of actuality, is there a way to consolidate these queries into one?
-Geates
NOTE: I'm programmer new to this particular forum and have only observatory knowledge with MSSQL. I appologize for any "questionables"
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding
These tables have 100,000s of rows
Audits_Assets:
pk | Host | Entity | Attrib | Value | TimeStamp
-----------------------------------------------
1 1 2 3 1 1
...
Audits_Logons:
pk | Host | Entity | Attrib | Value | TimeStamp
-----------------------------------------------
1 1 4 5 6 2
...
Audits_Values:
pk | Value
---------------
1 b-136615
2 Computer
3 HostName
4 Logon
5 CurrentUser
6 Geates
...
Audits_TimeStamps:
pk | Value
---------------
1 2/15/2011 3:16:00 PM
2 2/16/2011 9:30:00 AM
...
Code:
SELECT DISTINCT(tblLogons.Host) AS Host
tblTimeStamps.Value AS TimeStamp
FROM Audits_Logons AS tblLogons INNER JOIN
Audits_TimeStamps AS tblTimeStamps ON tblLogons.TimeStamp = tblTimeStamps.pk INNER JOIN
Audits_Values AS tblValues ON tblLogons.Value = tblValues.pk
WHERE (tblValues.Value LIKE '%something%')
GROUP BY tblLogons.Host
UNION
SELECT DISTINCT(tblAssets.Host) AS Host
tblTimeStamps.Value AS TimeStamp
FROM Audits_Assets AS tblAssets INNER JOIN
Audits_TimeStamps AS tblTimeStamps ON tblAssets.TimeStamp = tblTimeStamps.pk INNER JOIN
Audits_Values AS tblValues ON tblAssets.Value = tblValues.pk
WHERE (tblValues.Value LIKE '%something%')
GROUP BY tblAssets.Host
Based on this extremely crude representation of actuality, is there a way to consolidate these queries into one?
-Geates
NOTE: I'm programmer new to this particular forum and have only observatory knowledge with MSSQL. I appologize for any "questionables"
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding