We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,894 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

I need help in count query in rawsql

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 l.id = 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.

2
Contributors
3
Replies
1 Hour
Discussion Span
5 Months Ago
Last Updated
4
Views
Vijaysurya
Light Poster
35 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

what is structure and relation of poeple with layer table (how layer related to people)

urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

HAI,

here,i posted my table

Layer:
  columns:
    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 }
  relations:
    Personal: { local: personal_id, foreign: id, onDelete: CASCADE }


People:
  options:
    symfony: { form: false, filter: false }
  columns:
    layer_id:  { type: integer, primary: true }
    friend_id: { type: integer, primary: true }
  relations:
    Layer:  { local: layer_id, foreign: id, onDelete: CASCADE }
    Friend: { class: Personal, local: friend_id, foreign: id, onDelete: CASCADE }
Vijaysurya
Light Poster
35 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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
urtrivedi
Posting Virtuoso
1,714 posts since Dec 2008
Reputation Points: 299
Solved Threads: 362
Skill Endorsements: 24

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0671 seconds using 2.68MB