user1406951
user1406951

Reputation: 446

MySQL returns empty set seemingly at random

I can't figure out why MySQL is returning an empty set for only certain users in the following query. I have the same info entered in every single profile, and only a couple userid's will return a result.

SELECT userinfo.userid, userinfo.location, locations.locationsName, locations.locationsID FROM userinfo
INNER JOIN locations ON locations.locationsID = userinfo.userid
WHERE userinfo.userid = '$userid'

Here are my tables (there are more columns, but they're irrelevant to this search)

userinfo
userid | location 

locations
locationsID | locationsName

For example, I can open PHPMyAdmin and type in that query (changing the $userid). I made sure every single username has the same info entered (aside from having a different userid).

Upvotes: 0

Views: 205

Answers (1)

podiluska
podiluska

Reputation: 51504

Because you're joining the LocationID to the UserID.

Based on your given schema, you probably want to join userinfo.userid = location.userid

Upvotes: 1

Related Questions