0

For some reason my sql statement isn't return the three tables is there something wrong with my sql statement?

SELECT user.FirstName, user.LastName, user.Profilepix, userinterest.UserId, userinterest.InterestId 
FROM user 
INNER JOIN userinterest ON user.UserId = userinterest.UserId 
INNER JOIN interest ON userinterest.InterestId = interest.InterestId

userinterest maps both user and interest together.

EDIT** To add more detail no error is being thrown. The interest table is integer indexed so the userinterest contains the userId and interestId and I am trying to map all three and return the record

Kevlwig
  • 133
  • 2
  • 11
  • You'll have to be more specific. Is there an error when trying to run the query? Is no data at all being returned? Or is it just the row(s) you expect not being returned? – Justin Niessner Nov 12 '17 at 23:56
  • @JustinNiessner there is no error being thrown. The interest table isnt appearing – Kevlwig Nov 13 '17 at 00:00
  • From what you describe, there is nothing "wrong" with the syntax of your query. But we can see no data, or table definitions, so without at least 1 of those things (preferable both, but samples of the table data would really help) we have nothing to base recommendations on – Paul Maxwell Nov 13 '17 at 00:08

1 Answers1

8

You need to select the fields from the interest table if you want to see them. Here I am selecting all the fields with interest.*.

SELECT user.FirstName, user.LastName, user.Profilepix, userinterest.UserId, userinterest.InterestId, interest.*
FROM user 
INNER JOIN userinterest ON user.UserId = userinterest.UserId 
INNER JOIN interest ON userinterest.InterestId = interest.InterestId
Matt
  • 3,677
  • 1
  • 14
  • 24