select which referencing two tables