Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to filter results of this SQL query?

I’ve run a query to calculate the difference between values of two columns from two tables using a common key. The query is:

Select a.GPID, a.StartDate-b.StartDate as Discrepancy FROM Difftable1 a
INNER JOIN Difftable2 b
ON a.GPID= b.GPID;

and the results are here:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Results

But I want to filter the results to only include differences which equal -10000. Every attempt results in a syntax error. I’m new to SQL.

>Solution :

If you want to filter out -10000 from the result set, you can use

SELECT a.GPID, a.StartDate-b.StartDate as Discrepancy 
FROM Difftable1 a 
    INNER JOIN Difftable2 b ON a.GPID= b.GPID
WHERE a.StartDate-b.StartDate != -10000;

If you want to have records in the result set with only -10000, then replace != with = at the end of the above statement.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading