How do I use SELECT syntax inside WHERE for example I have following code:
SELECT
blah...blah..
...
WHERE
(
(APM_AlertsAndReportsData.ApplicationName = 'instance: tomcat6_noram (SNMP)') AND
(APM_AlertsAndReportsData.ComponentName = 'Memory Heap Used (B)') AND
(APM_AlertsAndReportsData.StatisticData >= 1908932600)
)
Here I am comparing values if its greater than or equal to 1908932600. I want to use SELECT in place of 1908932600 so it will automatically compare values rather than statically code in query.
You can use a subquery, you just need parentheses around it:
APM_AlertsAndReportsData.StatisticData >= (SELECT ... FROM ...)
Note that it may run slowly depending on what you are doing in your subquery. It might be better to use a JOIN instead.
You need a "correlated subquery" in the WHERE clause:
WHERE
(
(APM_AlertsAndReportsData.ApplicationName = 'instance: tomcat6_noram (SNMP)') AND
(APM_AlertsAndReportsData.ComponentName = 'Memory Heap Used (B)') AND
(APM_AlertsAndReportsData.StatisticData >= (SELECT SomeValue FROM SomeTable))
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With