Use where condition with unjoined table

Posted by Dragos D on Stack Overflow See other posts from Stack Overflow or by Dragos D
Published on 2012-10-14T09:29:12Z Indexed on 2012/10/14 9:37 UTC
Read the original article Hit count: 240

Filed under:
|

I have the following problem: I am trying to retreive a sum value based on one condition. Problem is that I can't join the conditional value since my tables aren't joined. Here is my syntax:

SELECT SUM(value)
FROM value v
  join day d on v.day_id = d.day_id
  join budget b on d.budget_id = b.budget_id
  join unit u on v.unit_id = u.unit_id
  where #output.class = (SELECT distinct s.class FROM sale s where s.id = #output.sale_id)
  AND u.unit_name in ('electronics')

With this sybtax I get no error but neither values.

Can you please tell me where I do wrong?

© Stack Overflow or respective owner

Related posts about sql

Related posts about tsql