Simple, hard selection



  • Table: m_frend friends. sl_frend (example 883 friends with 876) but there are other records uidYou're friends. m_frend (this is) m_frend I'll be there. sl_frendHom. Example 856 friends with 883.

    mysql> select * from frends ;
    +---------+----------+-------+
    | m_frend | sl_frend | fr_st |
    +---------+----------+-------+
    |     883 |      876 |     1 |
    |     880 |      875 |     1 |
    |     881 |      877 |     1 |
    |     856 |      883 |     1 |
    |     859 |      883 |     1 |
    |     860 |      883 |     1 |
    |     883 |      879 |     1 |
    |     883 |      880 |     1 |
    |     883 |      881 |     2 |
    +---------+----------+-------+
    9 rows in set (0.01 sec)
    

    You need to pull all your friends 883 out on one request, ELBICOM, and they're friends with 883.

    That's how the almbourc came out, I hope the prodlema was clear. And is it real?


    I know you can get it first.

    mysql> select * from frends where m_frend=883 or sl_frend=883;
    +---------+----------+-------+
    | m_frend | sl_frend | fr_st |
    +---------+----------+-------+
    |     883 |      876 |     1 |
    |     856 |      883 |     1 |
    |     859 |      883 |     1 |
    |     860 |      883 |     1 |
    |     883 |      879 |     1 |
    |     883 |      880 |     1 |
    |     883 |      881 |     2 |
    +---------+----------+-------+
    7 rows in set (0.00 sec)
    

    And then in the code, drop 883. But as a result of a request for one column?

    I don't know what headline to give this.



  • The design is good for these tasks. http://dev.mysql.com/doc/refman/5.7/en/union.html ♪ This type of request may be:

    SELECT sl_frend AS frend_id FROM frends WHERE m_frend = 883
        UNION SELECT m_frend AS frend_id FROM frends WHERE sl_frend = 883;
    

    Here's SQL Fiddle with http://sqlfiddle.com/#!9/27ee7/1 ♪




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2