tee
tee

Reputation: 1336

SQL subtracting values from two different tables in Access

I have two different tables that contain one value each. For example:

    table1               table2

|Hours_worked|        |Work_Completed|
     250                    346

I want my query to subtract Hours_worked from Work_completed. I tried this:

SELECT (SELECT Hours_worked FROM table1)- (SELECT Work_Completed FROM table2) AS Diff

I get the error: "Query input must contain at least one table or query"

Any help would be great, thanks

Upvotes: 0

Views: 1664

Answers (2)

Rafał Gołubowicz
Rafał Gołubowicz

Reputation: 660

Just add FROM dual, i mean:

 SELECT 
 (SELECT Hours_worked FROM table1) - (SELECT Work_Completed FROM table2) AS Diff
 FROM DUAL

Upvotes: 0

Avitus
Avitus

Reputation: 15968

I think it would just be:

select Hours_worked - Work_Completed as diff
from table1, table2

Upvotes: 2

Related Questions