Помогите составить SELECT

Discussion in 'PHP' started by The46Doctor, 7 Feb 2013.

Thread Status:
Not open for further replies.
  1. The46Doctor

    The46Doctor New Member

    Joined:
    31 May 2012
    Messages:
    44
    Likes Received:
    0
    Reputations:
    0
    Есть таблица people. В ней два поля id, name.
    Как вывести id тех записей в которых поле name повторяeтся 3 раза? То есть:
    id |name
    ------------
    1 |коля
    2 |миша
    3 |коля
    4 |коля
    5 |миша

    запрос должен вывести 1, 3, 4
     
  2. kroŧ

    kroŧ Member

    Joined:
    19 May 2010
    Messages:
    141
    Likes Received:
    33
    Reputations:
    8
    Code:
    select id, name from people group by name having COUNT(*)=3;
     
  3. The46Doctor

    The46Doctor New Member

    Joined:
    31 May 2012
    Messages:
    44
    Likes Received:
    0
    Reputations:
    0
    Неа) Выводит только первое вхождение строки.
    В моем случаи вернет 1|коля
     
  4. Gifts

    Gifts Green member

    Joined:
    25 Apr 2008
    Messages:
    2,494
    Likes Received:
    807
    Reputations:
    614
    The46Doctor select group_concat(id), name from people group by name having COUNT(*)=3;

    https://forum.antichat.ru/thread62769.html
     
    _________________________
Loading...
Thread Status:
Not open for further replies.