views:

26

answers:

1

In a table I have news posts with these fields:

  • Title
  • Content
  • OwnerID

And a users table

  • ID
  • Name
  • Surname

The OwnerID relates to the ID in the users table, how can I get the name of the user who's ID matches the OwnerID?

I'm writing a website in ASP.net (VB).

+2  A: 

You would need to join the two tables together like this:

select users.Name
from news inner join users
    on OwnerID = ID;

This query has no where clause to filter the results that are returned so this query would return all users who are associated with a news record. If you wanted to find users associated with a specific news record you would need to filter on the news title or content like this:

select users.Name
from news inner join users
    on OwnerID = ID
where Title = 'Some Title';
Andrew Hare