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

  • Home
  • SEARCH
  • 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 8996755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:47:50+00:00 2026-06-15T23:47:50+00:00

I have a doctrine based application where I want to select rows from two

  • 0

I have a doctrine based application where I want to select rows from two separate tables and order them by creation date. I’m (sort of) accomplishing it this way right now:

$query = $em->createQueryBuilder()
  ->from('Embed', 'e')
  ->select("e")
  ->leftJoin("User", "u", "WITH", "e.uid=u.id")
  ->leftJoin("Product", "p", "WITH", "e.pid=p.id")
  ->where("u.image > 0 OR p.image > 0")
  ->addOrderBy("u.timeCreated + p.timeCreated", "DESC")
  ->setMaxResults(28)
  ->getQuery();

I would like for product and user data to be mixed, ordered by creation date, but the ordering is incorrect. I’ve also tried using two addOrderBy statements, which orders users and products correctly but puts all the users first in the results, rather than mixing them.

EDIT: Sir Rufo had the correct approach – here’s the working code:

$query = $em->createQueryBuilder()
  ->from('Embed', 'e')
  ->select("e")
  ->leftJoin("User", "u", "WITH", "e.uid=u.id")
  ->leftJoin("Product", "p", "WITH", "e.pid=p.id")
  ->addSelect('COALESCE( u.timeCreated, p.timeCreated ) as timeCreated')
  ->where("u.image > 0 OR p.image > 0")
  ->orderBy("timeCreated", "DESC")
  ->setMaxResults(28)
  ->getQuery();
  • 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-15T23:47:50+00:00Added an answer on June 15, 2026 at 11:47 pm

    You should try this

    $query = $em->createQueryBuilder()
      ->from('Embed', 'e')
      ->select("e")
      ->leftJoin("User", "u", "WITH", "e.uid=u.id")
      ->leftJoin("Product", "p", "WITH", "e.pid=p.id")
      ->where("u.image > 0 OR p.image > 0")
      ->addOrderBy("COALESCE( u.timeCreated, p.timeCreated )", "DESC")
      ->setMaxResults(28)
      ->getQuery();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I want to assemble a Doctrine select query based
I have a Symfony application that uses Doctrine as its ORM. Based on Symfony's
Elloo, I have two doctrine entities and am trying to do left join however
I have some models witch are using Doctrine nestedset feature. I want to add
I have a problem with saving the path in doctrine from a file upload.
I have an application that I'm converting to Symfony/Doctrine. It currently stores a serialized
My application based on Zend Framework and Doctrine includes > 300 files on each
Using Symfony and Doctrine, I have a multi-select list box. The multiple default values
tl;dr: I need to show data from two different tables in the list view
im using doctrine-project and i have 3 tables table 1: post -------------- postid ,

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.