Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:54:31+00:00 2026-06-04T14:54:31+00:00

I generate an SQL from NativeQuery and this is the result sql: SELECT COUNT(id)

  • 0

I generate an SQL from NativeQuery and this is the result sql:

SELECT COUNT(id) AS tot,created_at FROM property WHERE created_at
BETWEEN ‘20120501000000’ AND ‘20120521235959’ GROUP BY
YEAR(created_at),MONTH(created_at),DAY(created_at);

This is my ResultSetMapping:

$rsm = new \Doctrine\ORM\Query\ResultSetMapping;
$rsm->addEntityResult('Entity\Property', 'p');
$rsm->addFieldResult('p','count(id)','tot'); // <-- this don't work
$rsm->addFieldResult('p','created_at','created_at');

The result running the above query direct on mysql is ok:

tot created_at
11  2012-05-02 11:23:25
11  2012-05-08 14:56:40
152 2012-05-16 14:43:46
5   2012-05-17 16:26:31
29  2012-05-18 14:55:33

But the result array the tot alias don’t exist!!

The Question is:

How i set ResultSetMapping correctly for count(id)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:54:33+00:00Added an answer on June 4, 2026 at 2:54 pm

    I would try:

    $rsm->addFieldResult('p', 'tot', 'tot');
    

    as your column as been renamed with COUNT(id) AS tot. If remove the tot alias you can use your original code:

    $rsm->addFieldResult('p', 'COUNT(id)', 'tot');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to generate this SQL statement in LINQ: select * from Foo where
This is from a sql script. What tool can generate this? Thanks --USE [MY_TABLE]
ive a similar problem as this guy: Generate SQL CE database from EF Code-First
I want to generate SQL like this: SELECT coalesce(max(a.a_index) + 1, 0) as a_index
I want to generate a dynamic SQL where clause from a Scala collection, such
I'm writing a PHP script to generate SQL dumps from my database for version
I'm trying to generate SQL table header from a csv file. As I had
How to generate sql script file from C# codebehind? The script file will contain
This is the same question as: How to dynamically generate SQL query based on
I'm trying to connect to SQL DB from Server Explorer to generate context classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.