tags:

views:

39

answers:

4

I have tables:

 users
    with the fields id, premium
 votes
    with the fields userid, date.

How do I select ALL THE VOTES from ALL USERS FROM TODAY only when premium = 'yes' ?

+1  A: 
select * from votes v, users u 
where v.userid = u.id and u.premium = 'yes' 
      and v.date = today()
Wim
yes but I need to count all the votes from all the users
FinalDestiny
Your question says "select all the votes", I was assuming there are some other fields in `votes` that you need. What exactly do you need to be counted? All votes per user? Or all votes over all users?
Wim
all the votes for all the premium users
FinalDestiny
+3  A: 

Use:

SELECT COUNT(*)
  FROM VOTES v 
  JOIN USERS u ON u.id = v.userid
              AND u.premium = 'yes'
 WHERE v.date = CURRENT_DATE()
OMG Ponies
this query is not working
FinalDestiny
not working , gives Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /
FinalDestiny
@FinalDestiny look for an error from the mysql_query call rather than the fetch.
ar
A: 
SELECT votes.* FROM users, votes WHERE users.Id = votes.userid WHERE premium='yes' AND date=DATE(NOW())
adharris
+1  A: 
select count(a.id) from users a, votes b where a.id=b.userid and a.premium='yes' and b.date=CURDATE() 
Pradeep