문제

I have two tables.

Users - Has 2 foreign keys reg_ip and last_ip which both reference the second table column id.

users

+--------+---------+
| reg_ip | last_ip |
+--------+---------+
|      1 |       2 |
+--------+---------+

ips

+----+---------+
| id | user_ip |
+----+---------+
|  1 | 1.2.3.4 |
|  2 | 2.3.4.5 |
+----+---------+

I have been trying to query in such a way that it will return 1.2.3.4 and 2.3.4.5 in one result but I have not been successful. I would be appreciative for a working answer.

Thank you.

도움이 되었습니까?

해결책

Try this:

SELECT GROUP_CONCAT(DISTINCT i.user_ip)
FROM ips i 
INNER JOIN users u ON i.id IN (u.reg_ip, u.last_ip)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top