I am posting this because I know I will need this soon or later.
I have built a simple recommendation for one of the websites I work with. It is only based on social relationships and does not take into account other parameters. The basic idea is if I like an item, select other items liked by people who also like this item and it can be used to build lists of similar items as seen on Amazon or YouTube. If we use as an example people who like movies (tables Person, Movie and many-to-many relationship PersonMovie), this can be expressed in SQL using several joins:
SELECT DISTINCT Movie.*, COUNT(Person.ID) AS PersonCount FROM Movie JOIN PersonMovie ON Movie.ID = PersonMovie.MovieID JOIN Person ON PersonMovie.PersonID = Person.ID JOIN PersonMovie AS PersonMovie1 ON Person.ID = PersonMovie1.PersonID JOIN Movie AS Movie1 ON PersonMovie1.MovieID = Movie1.ID WHERE Movie1.ID = 1 AND Movie.ID != Movie1.ID GROUP BY Movie.ID ORDER BY PersonCount DESCFirst we join movies to people and then backwards to the specific movie with ID = 1 that we want to get similar movies for. PersonCount is the relevance factor — the higher it is, the more people like the movie.