How can I start the following query?
I have three tables hasfriend
, person
and message
.
I want to run the following SQL query, output all persons once who have sent a message and are friends with a certain person.
The tables are constructed as follows:
hasfriend
consists of: email, emailfriendmessage
consists of: id, fromemail, toemailperson
consists of: email, firstname, lastname
So my query now looks like this:
SELECT DISTINCT person.firstname, person.lastname
FROM hasfriend, person, message
WHERE hasfriend.emailfriend = 'max.muster@mail.de'
AND (message.fromemail = person.email)
But it's not a good solution because the hasfriend.email
is fixed. How can I solve this better?