I’ve a complex query and I can’t get the correct answer.
There are 3 tables:
contact (pk as INT, name as VARCHAR, …)
session (pk as INT, contact as INT, …)
message (pk as INT, session as INT, …)
The session.contact points to contact.pk. And message.session to session.pk.
When session.contact is zero, then there is no contact for this row. contact.pk is never zero.
Now I want to get all names of the specific message. My try was this:
SELECT message.pk, contact.name FROM message, session, contact WHERE message.session = session.pk AND session.contact = contact.pk
But I didn’t get the correct number of rows returned. It should be 2459, there are 2075.
First, how do you know that is the correct number of rows?
Second, you should use proper
JOINsyntax similar to below: