How to query in a friend's table and own the same friends and not own friends of the user

Source: Internet
Author: User
How to query in a friend table and own users who have the same friends and are not their own friends


The UID and the friend ID are all in the other table.
How to query in a friend table and own users who have the same friends and are not their own friends

------Solution--------------------
There are at least two fields in Friends table friend, user_id fields and friend_id fields
1. First find out your friends: 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 US er_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.