I have a table (user) that contains user information.
I have another table (userview) that records user views - that is, when one user views another users details, I record the id of the viewer and also, the id of the user he/she viewed.
I want to write a query that will help me answer the question:
Fetch the list of ALL users that were viewed by users that viewed a SPECIFIED user.
It seems a straight forward enough innocous requirement, but I am coming up with SQL that is (atleast to my mind), far too complicated. I think an elegant solution would use a self join on userview and (possibly?) an inner join between user and userview.
Are there any SQL 'poets' out there that can help with this?
I am using mySQL 5.x, but ideally the SQL should be fb agnostic