Matt Coelho
Matt Coelho

Reputation: 11

Getting another table's record based on matching IDs

I have 2 tables

Table 1: dit_news

1. id
2. title
3. body
4. date
5. posterID

Table 2: dit_users

1. id
2. fullName
3+ a bunch of irrelevant to this problem columns

dit_news.posterID equals that of dit_users.id

I need a way of getting the fullName record where the dit_users's ID equals that of posterIDin dit_news. I hope that makes sense. Any help would be greatly appreciated.

Upvotes: 1

Views: 100

Answers (4)

Yuriy
Yuriy

Reputation: 1984

SELECT
    dit_users.fullName
FROM
    dit_news
    JOIN dit_users ON
        dit_news.posterID = dit_users.id
;

You may want to add WHERE dit_news.id = N to retrieve the name of the user for article N only.

Upvotes: 0

juergen d
juergen d

Reputation: 204756

select distinct u.fullName
from dit_users u
inner join dit_news n on n.posterID = u.id

Upvotes: 0

mvp
mvp

Reputation: 116098

SELECT u.fullname
FROM dit_users u
   JOIN dit_news n ON (n.posterid = u.id)
WHERE n.id = 12345

Upvotes: 0

David
David

Reputation: 20063

SELECT dit_users.fullName FROM ditusers INNER JOIN dit_news ON dit_users.id = dit_news.posterID

Upvotes: 2

Related Questions