Daniel Pilch
Daniel Pilch

Reputation: 2257

Getting a column of data from a different table MySQL

I'm not very competent with MySQL joins so I would appreciate some help.

I have two tables. Lets call them X and Y.

X is the main table, however I want to get one column of data from table Y where the site_id in table X corresponds to the site_id in table Y.

Example scheme for table X: id, site_id, notes

Example scheme for table Y: id, site_id, name

I would like to then create a query to have id, site_id, notes, name where name corresponds to the site_id

Can anyone help?

Thanks

Upvotes: 0

Views: 31

Answers (1)

Andrius Naruševičius
Andrius Naruševičius

Reputation: 8578

SELECT
    X.id, 
    X.site_id, 
    X.notes, 
    Y.name
FROM
    X
    LEFT JOIN Y ON X.site_id = Y.site_id

Upvotes: 1

Related Questions