Forum Moderators: open
The two tables are like:
users: idnum, username, password, lastlogin as date
messages: msgnum, subject, body, date_received as date
The query which ALMOST works is:
select idnum, lastlogin, count(msgnum) FROM users, messages WHERE username='USER' AND password=md5('PWD')
AND (date_received > lastlogin) GROUP BY msgnum
...but this clearly fails to authorise someone who has no new messages, so that won't do. Any ideas, folks?
TIA
Welcome to WebmasterWorld!
Something like this should work:
SELECT idnum, lastlogin, count(msgnum)
FROM users left outer join messages on users.lastlogin < messages.date_received
WHERE username='USER' AND password=md5('PWD')
GROUP BY msgnum
By doing an outer join, it will still return results even if there are no records that can be joined. I didn't test that query, so you might have to tweak it a bit, but hopefully it'll set you on the right track.
Chad