How do I show list people who have relationship with logged in user

Hi guys,
I have these two simple tables:

TB1
tb1_id	tb1_name
1	Red
2	Blue
3	Yellow

TB2
tb2_id	tb2_id1	tb2_id2	tb2_type	 tb2_value
1	3	1	A		2

How do I show list of users who have relationship with user id of 3. I’ve tried this and it’s not working?

SELECT
	tb2_id1, tb2_id2, tb2_type, tb2_value, tb1_id, tb1_name
FROM
	TB2
LEFT JOIN
	TB1
	ON
		tb2_id1 = tb1_id OR tb2_id2 = tb1_id
WHERE
	(tb2_id1 = :user_id OR tb2_id2 = :user_id) AND tb2_type = :tb2_type AND tb2_value = :tb2_value AND RAND()<(SELECT ((15/COUNT(*))*10) FROM TB2)
ORDER BY
	RAND()
LIMIT
	15

The one I want to show on the list is a guy called Red.

Thank you,

Folk on stackoverflow helps me solved problem here: http://stackoverflow.com/questions/38277192/how-to-left-join-with-or-operator-and-determined-only-one-column-that-match/38277944#38277944

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.