Select syntax inside WHERE

sql, sql-server

Solution

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.

Problem

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.

Original source