SELECT + razlika dveh vrednosti iz dveh tabel

Pozdrav!

Zanima me, kako v enem mysql stavku izvesti tole (če se da). Imam dve tabeli:
projects
| id | places |
| 1 | 20 |

registered
| id | project |
| 1 | 1 |

..moram odšteti

projects.places - num_rows(SELECT * FROM registered WHERE registered.project=projects.id)

Upam da je dokaj razumljivo napisano.

Lp, Jure!

2 odgovora

Tole bi moglo delat:

SELECT (places - (SELECT count(project) FROM registered WHERE registered.project=projects.id)) as total FROM projects GROUP BY projects.id

SELECT A.places - B.project AS rezultat FROM projects A LEFT OUTER JOIN registered B
ON A.id = B.id

Preveril nisem, moralo pa bi delati....