How to query users who have the same friends and are not friends in a friend table

Source: Internet
Author: User
In a friend table, how does one query User uid and friend ID that have the same friends and are not friends? in another table, how does one query in a friend table is the same as the user ID? users of friends who are not friends of their own, the friend table has at least two fields: user_id and friend_ I. how can I query users who have the same friends and are not friends in a friend table?


Uid and Friend ID are both in another table.
How to query users who have the same friends and are not friends in a friend table?

------ Solution --------------------
The friend table has at least two fields: user_id and friend_id.
1. First, find out your friend: select friend_id from friend where user_id = "zhangshan ";
2. select distinct user_id from friend where friend_id in (select friend_id from friend where user_id = "zhangshan") and user_id! = "Zhangshan" and user_id not in (select friend_id from friend where user_id = "zhangshan ");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.