I need to create a query that suggests artists to users depending on what they like and what other people who like what they like like. Hope you get that.
Anyhow, the tables in question are members (self explanatory) and artist_follows (which members follow who). I will add this query into a bigger query later on that will also get the artist info from the artists table for that ID.
Here’s what I have so far, i’ve used 2 as the mock ID for the member.
SELECT
M.ID AS M_ID,
F.ID AS F_ID,
F.follows_ID
FROM members M
LEFT JOIN artist_follows F
ON F.ID = M.ID
WHERE M.ID ='2'
I realise its not very much at all but its as far as I can get hence why I came here.
Heres a breakdown of what needs to be done:
1: Get ID from members table.
2: Get follows_ID (who the user follows) from artist_follows by using the members ID
3: Get IDS of people who follow who the member follows. (call this “other members IDS” for the purpose of the next point).
4: Get other artists IDS from “other members IDS” making sure artists that are already followed by the member aren’t selected.
Hope breaking it down like that has helped!
UPDATE!
Lets have some mock data as suggested then. Lets say the member 2 follows artists with IDS 3 . Another member (4) follows 3 as well as 20. The outcome of the query should therefore be 20
Schema:
artist_follows;
CREATE TABLE `artist_follows` (
`ID` int(11) NOT NULL,
`follows_ID` int(11) NOT NULL,
KEY `fav_ID` (`ID`),
CONSTRAINT `fav_ID` FOREIGN KEY (`ID`) REFERENCES `artists` (`ID`),
CONSTRAINT `ID` FOREIGN KEY (`ID`) REFERENCES `members` (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
members;
CREATE TABLE `members` (
`ID` int(111) NOT NULL AUTO_INCREMENT,
`email` varchar(100) COLLATE latin1_general_ci NOT NULL,
`password` varchar(100) COLLATE latin1_general_ci NOT NULL,
`FNAME` varchar(100) COLLATE latin1_general_ci NOT NULL,
`SURNAME` varchar(100) COLLATE latin1_general_ci NOT NULL,
`timestamp` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`ID`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci
1 Answer