# Report Building SQL Query. Identify machines that have vulnerabilities and also those with vulnerabilities remediated

**URL:** <https://discuss.rapid7.com/t/report-building-sql-query-identify-machines-that-have-vulnerabilities-and-also-those-with-vulnerabilities-remediated/2254>\
**Category:** SQL Queries\
**Tags:** InsightVM\
**Created:** [October 24, 2020, 3:09am UTC](https://discuss.rapid7.com/t/report-building-sql-query-identify-machines-that-have-vulnerabilities-and-also-those-with-vulnerabilities-remediated/2254 "2020-10-24T03:09:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![patrick\_doudna](https://discuss.rapid7.com/letter_avatar_proxy/v4/letter/p/e47c2d/32.png) [@patrick\_doudna](https://discuss.rapid7.com/u/patrick_doudna)\
**Post date:** [October 24, 2020, 3:09am UTC](https://discuss.rapid7.com/t/report-building-sql-query-identify-machines-that-have-vulnerabilities-and-also-those-with-vulnerabilities-remediated/2254/1 "2020-10-24T03:09:58Z")

</div>

This my first foray into SQL so bear with me.

I am looking to create a report based on vulnerability that tells me what hosts have been patched and those that are not patched how long they have been unpatched.

This is the query that I stitched together:  
_\> SELECT favf.vulnerability\_id, favf.asset\_id, da.ip\_address, da.host\_name, fava.first\_discovered, fava.age\_in\_days, dv.title, favrd.date_  
_\> FROM fact\_asset\_vulnerability\_finding favf_  
_\> JOIN fact\_asset\_vulnerability\_remediation\_date favrd ON favf.asset\_id = da.asset\_id_  
_\> JOIN dim\_asset da ON favf.asset\_id = da.asset\_id_  
_\> JOIN dim\_vulnerability dv ON favf.vulnerability\_id = dv.vulnerability\_id_  
_\> JOIN fact\_asset\_vulnerability\_age fava ON favf.vulnerability\_id = fava.vulnerability\_id_  
_\> WHERE dv.title LIKE ‘%CVE-2020-16947%’_

its failed with the following error:  
_ **Error:** relation “fact\_asset\_vulnerability\_remediation\_date” does not exist_  
_ **Character:** 185_

More than anything I am intrigued by fact\_asset\_vulnerability\_remediation\_date not existing. Am I not calling upon it right?

---

<div class="post-metadata">

**Author:** ![holly\_wilsey](https://discuss.rapid7.com/user_avatar/discuss.rapid7.com/holly_wilsey/32/78_2.png) [@holly\_wilsey](https://discuss.rapid7.com/u/holly_wilsey)\
**Post date:** [October 27, 2020, 12:50am UTC](https://discuss.rapid7.com/t/report-building-sql-query-identify-machines-that-have-vulnerabilities-and-also-those-with-vulnerabilities-remediated/2254/2 "2020-10-27T00:50:45Z")

</div>

It sounds like you’re running your query from the InsightVM console here, in which case the `fact_asset_vulnerability_remediation_date` table doesn’t exist. This table does exist in the data warehouse, which is an external warehouse where you can export your InsightVM data to get richer data for things like reporting.

If you have queries that you want to run from the console itself, then you can reference the reporting data model [here](https://docs.rapid7.com/insightvm/understanding-the-reporting-data-model-facts) and [here](https://docs.rapid7.com/insightvm/understanding-the-reporting-data-model-dimensions/) to see what tables + fields exist.

If you do want to setup the data warehouse and run queries there (where the table you mentioned does exist), we’ve got some info on [how to get started](https://docs.rapid7.com/insightvm/configuring-data-warehousing-settings/#deploying-and-configuring-the-warehouse). We also have the [schema](https://help.rapid7.com/nexpose/en-us/warehouse/warehouse-schema.html) for the data warehouse if you want to further delve into its tables + fields.

So in short, there’s the reporting data model vs. the data warehouse model, and they don’t always line up 1:1 in terms of table names, columns, and relationships.
