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 6229677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:36:50+00:00 2026-05-24T09:36:50+00:00

I need to create native SQL query with couple of unions and subqueries. It’ll

  • 0

I need to create native SQL query with couple of unions and subqueries. It’ll look approximately like this:

SELECT res.id, COUNT(*) as count_ids
FROM (
    SELECT a.id FROM ... a WHERE ... LIKE ('%:param%')
    UNION ALL
    SELECT b.id FROM ... b WHERE ... LIKE ('%:param%')
    UNION ALL
    ...
) res
GROUP BY res.id
ORDER BY count_ids asc

Result won’t match any Entity I use in my application. Is it possible to create ResultSetMapping with “anonymous” object? Or is it, at least, possible to create an Entity that wouldn’t create table next time I update schema, so I can map results to it?

Or is there any other Doctrine-friendly way to deal with such query? Making changes to database isn’t possible though, as I’m dealing with legacy stuff that cannot be touched. I’d also strongly prefer if I did everything on database side, not involving much of PHP in it.

  • 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-05-24T09:36:51+00:00Added an answer on May 24, 2026 at 9:36 am

    Do you have a particular need to map results to a domain object? If not, you could use the DBAL to make a plain old query, which will return an array, as detailed in the Symfony2 cookbook and the Doctrine DBAL documentation:

    $conn = $this->container->get('database_connection');
    $sql = 'SELECT res.id, COUNT(*)...';
    $rows = $conn->query($sql);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
For my application (an MMC snap-in) I need to create a single native DLL
I need to create a backup of a SQL Server 2005 Database that's only
I used schemaExport to create my tables like this Configuration config = new Configuration();
I need to create a query in NHibernate that would search for a product
I need to reverse engineer a Microsoft SQL Server 2008 in order to create
i would like to have a query that will solve my problem in native
I need to create a binary blob of empty data to PInvoke a native
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution

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.