K. Shores
K. Shores

Reputation: 1005

SQL, Inner join, replacing id with name

I am making a distributed system that is like Twitter where users can follow other users. I am using a mysql server database to store the data.

The tables that I have are:

I would like to get a list of followers for a certain id. The statement that I am trying to use is SELECT name FROM Follower INNER JOIN User USING(id) WHERE Follower.id = <some_id>

That is, I would like all names of all followers for some id. The above is a syntax error, but I am not sure what I am doing wrong. Which part of my statement is incorrect?

Upvotes: 2

Views: 5508

Answers (2)

AamirR
AamirR

Reputation: 12208

You have an incomplete SQL statement, the ON clause on JOIN seems missing, try this:

SELECT User.name FROM Follower
INNER JOIN User ON User.id=Follower.followerId
WHERE Follower.id = <some_id>

Upvotes: 2

Satya Prakash
Satya Prakash

Reputation: 696

Select U.name from User U  
inner join  Follower F on U.id=F.followerId
Where F.id=<some_id>

You can also get other respective field

Upvotes: 2

Related Questions