Start New Discussion within our Web Development Community

Hai everybody,

I need help in doctrine raw sql query,

this query count not properly,

$query = $db->prepare("SELECT count(p.friend_id) AS count , p.layer_id, l. *
                                        from layer l, people p
                                        where l.personal_id = :personal_id
                                        and = p.layer_id


layer_id           friend_id
5                     2
6                     7
5                       3

this is my people table structure,

this query display result  count 2 in layer_id 6.

my expected result is

layer_id  count
5             2

 6            1

anybody plz help me.


here,i posted my table

    personal_id:     { type: integer, notnull: true }
    name:            { type: string(255), notnull: true }
    picture_id:      { type: integer, primary: true }
    privacy_setting: { type: string(64), notnull: true }
    view_notifications_in_this_layer: { type: integer, notnull: true }
    Personal: { local: personal_id, foreign: id, onDelete: CASCADE }

    symfony: { form: false, filter: false }
    layer_id:  { type: integer, primary: true }
    friend_id: { type: integer, primary: true }
    Layer:  { local: layer_id, foreign: id, onDelete: CASCADE }
    Friend: { class: Personal, local: friend_id, foreign: id, onDelete: CASCADE }

if I see expected result I guess no need to join tables, you can simple do following query with only layer table

select layer_id, count(*) count from layer group by layer_id
This article has been dead for over six months. Start a new discussion instead.