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,