Jeremy John
Jeremy John

Reputation: 1715

Select two columns from two table with conditions

I want to

 SELECT table1.columnA FROM table1 + ORDER BY id DESC LIMIT 1; //to get last row

and

SELECT SUM(table2.columnB) FROM table2

and then i want to do a minus condition like

SELECT table1.columnA FROM table1 ORDER BY id DESC LIMIT 1 - SELECT SUM(table2.columnB) FROM table2

but it does not work.

Upvotes: 2

Views: 198

Answers (1)

sagi
sagi

Reputation: 40481

If what you want is the result between subtracting the sum of columnB from columnA so use this:

SELECT table1.id,table1.columnA -(select sum(columnB) from table2) as YourColumn
FROM Table1
ORDER BY table1.id desc LIMIT 1

Upvotes: 2

Related Questions