Jump to content

Bull

Members
  • Posts

    2
  • Joined

  • Last visited

Bull's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. Thank you for your answer dooberry.Meanwhile, I have found the solution. Here is the query:SELECT Accounts.*, SUM (CASE WHEN emails.read=0 THEN 1 ELSE 0 END) AS nbUnread FROM Accounts LEFT OUTER JOIN emails ON Accounts.id=emails.account GROUP BY Account.id
  2. Dear all,I tried to retrieve information from two tables.Here is the structure of my first table: Table Accountsid as integername as stringetc. And the second one: Table emailsid as integeraccount as integerread as boolean So this is very easy: my first table contains the email accounts and the second one, the emails as such. What I would like to retrieve is all the accounts and, for each of them, the number of unread emails. I think I am not so far away from the solution with such query: SELECT *,count(*) as nb FROM (SELECT * FROM accounts JOIN (SELECT account, read FROM emails WHERE read=False) as emails ON accounts.id=emails.account) as accounts GROUP BY accounts.account Problem with this query: it only retrieves the accounts which have unread emails. So how to retrieve also the accounts which all emails are read with the number of unread messages set to 0?Thank you very much for your supportBest regards
×
×
  • Create New...