MySQL Query from two tables
I have a database with two tables: members
and profilefields
.
members
has columns: ID, name, email
profilefields
has columns:ID, field1, field2, etc.
I would like to select name
and email
for each row in members
, based on the queryprofilefields
I think this is how it works, but I don't know how to make the request:
Get Id From profilefields
Where field1 = X
AND field2 = Y
Get name and email from members for those Ids
I am really new to this so I am very grateful for any help.
source to share
This should do the trick:
SELECT
m.name,
m.email
FROM
members m
INNER JOIN profilefields pf ON
m.ID = pf.id
WHERE
pf.field1=X AND
pf.field2=Y
Here we use INNER JOIN
in a sentence FROM
to link tables in their field id
. The filter goes to the offer WHERE
, and the fields you want to return are in the offer SELECT
.
source to share