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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:30:16+00:00 2026-05-31T02:30:16+00:00

I need to perform this query: SELECT * FROM (SELECT * FROM product WHERE

  • 0

I need to perform this query:

SELECT * FROM (SELECT * FROM product WHERE car = 'large' ORDER BY onSale DESC) AS product_ordered GROUP BY type

In Symfony2 using the entity manager.

My basic query builder would be :

 $query = $em->getRepository('AutomotiveBundle:Car')
        ->createQueryBuilder('p')
        ->where('pr.car = ?1')
        ->andWhere('pr.status = 1')
        ->orderBy('pr.onSale', 'DESC')
        ->setParameter(1, $product->getName())
        ->groupBy('p.type')
        ->getQuery();

But I cannot work out how to add in a subquery to this.

Ive tried making a separate query and joining it like:

 ->andWhere($query->expr()->in('pr.car = ?1',$query2->getQuery()));

But I get:

Call to undefined method Doctrine\ORM\Query::expr()
  • 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-31T02:30:18+00:00Added an answer on May 31, 2026 at 2:30 am

    One trick is to build two queries and then use getDQL() to feed the first query into the second query.

    For example, this query returns a distinct list of game ids:

        $qbGameId = $em->createQueryBuilder();
    
        $qbGameId->addSelect('distinct gameGameId.id');
    
        $qbGameId->from('ZaysoCoreBundle:Event','gameGameId');
    
        $qbGameId->leftJoin('gameGameId.teams','gameTeamGameId');
    
        if ($date1) $qbGameId->andWhere($qbGameId->expr()->gte('gameGameId.date',$date1));
        if ($date2) $qbGameId->andWhere($qbGameId->expr()->lte('gameGameId.date',$date2));
    

    Now use the dql to get additional information about the games themselves:

        $qbGames = $em->createQueryBuilder();
    
        $qbGames->addSelect('game');
        $qbGames->addSelect('gameTeam');
        $qbGames->addSelect('team');
        $qbGames->addSelect('field');
    
        $qbGames->addSelect('gamePerson');
        $qbGames->addSelect('person');
    
        $qbGames->from('ZaysoCoreBundle:Event','game');
    
        $qbGames->leftJoin('game.teams',   'gameTeam');
        $qbGames->leftJoin('game.persons', 'gamePerson');
        $qbGames->leftJoin('game.field',   'field');
    
        $qbGames->leftJoin('gameTeam.team',     'team');
        $qbGames->leftJoin('gamePerson.person', 'person');
    
        // Here is where we feed in the dql
        $qbGames->andWhere($qbGames->expr()->in('game.id',$qbGameId->getDQL()));
    

    Kind of a long example but i didn’t want to edit out stuff and maybe break it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to perform this Oracle query in SQL Server: select case_id, channel_index, min(su_min)
I need to perform a filtered query from within a django template, to get
I need to perform a LINQ query for both a time period from a
select p.Id, sum(inc.Quantity) from Products p join Incomes inc group by p.Id order by
So I have this query: select ens_use_new_models_bit from cfo_transaction inner join dbo.cfo_trans_entity_rel on te_tr_transaction_id=tr_transaction_id
I need to perform a HTTP GET from PHP. More specifically, from within /index.php
I need to select a top row for each category from a known set
I am trying to get ActiveRecord to perform the following query: SELECT A.*, B.*,
Aloha, I need to run a simple ( SELECT * FROM tbl1 WHERE Col1=x
Essentially I need to group unique product data into a single row when: The

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.