SQL join on multiple columns in same tables

You need to replace the second ON with AND, like this:

ON a.userid = b.sourceid AND a.listid = b.destinationid;

Leave a Comment