Reputation: 16154
Why this query returns 0? I want to get a number of messages, that have the folderName 'INBOX'. Messages and Folders tables are connected via FolderID.
"SELECT COUNT(*) FROM Messages AS m \
LEFT JOIN Folders AS f \
ON m.FolderID = f.FolderID \
WHERE f.FolderName = 'INBOX'"
I exactly know, that there are messages with this folder ID's. The problem is in sql.
Upvotes: 0
Views: 276
Reputation: 5808
SELECT COUNT(*) FROM Messages AS m
INNER JOIN Folders AS f
ON m.FolderID = f.FolderID
WHERE UPPER(f.FolderName) = 'INBOX'
It needs to be an inner join and depending on the case sensitivity of the SQL server set up you may need to think about matching case.
Upvotes: 1