-1

I am trying to select some data from two tables, where some conditions has to be true. I am trying to join to AND/OR statements together.

select 
    a.token, a.fixed_expire, b.token, b.username, COUNT(DISTINCT a.token) adcount, 
    COUNT(DISTINCT b.username) clickcount
    from advertisements a 
    JOIN advertisement_clicks b ON b.token=a.token
    where a.status='2' AND (a.clicks_left > 0 OR a.daily ='1' OR a.fixed='1' AND(a.fixed_expire>'2'))

So, above query doesn't work. My question is, how can I join the OR a.fixed='1' AND(a.fixed_expire>'2') inside the original AND operation?

If a.fixed='1' then it should check for a.fixed_expire>2

oliverbj
  • 5,771
  • 27
  • 83
  • 178

1 Answers1

0

(a.clicks_left > 0 OR a.daily ='1' OR a.fixed='1' )AND(a.fixed_expire>'2')

You should group OR statements

Eveis
  • 202
  • 1
  • 2