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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:14:16+00:00 2026-06-11T11:14:16+00:00

I need to do self join using Symfony 1.4/Propel 1.4. My tables/db are too

  • 0

I need to do self join using Symfony 1.4/Propel 1.4. My tables/db are too big to put here but an example table is given below to replicate the issue I’m facing.

Consider following example table with example data

Table Employee
----------------------------------------
|id    | name                    | mid |
----------------------------------------
|1     | CEO                     |NULL |
|2     | CTO                     |1    |
|3     | CFO                     |1    |
|4     | PM1                     |2    |
|5     | TL1                     |4    |
----------------------------------------

Here first column is employee, second is employee name and 3rd is manager id. mid is link to another row in same table. For example, CTO(2) reports to CEO(1) so mid in second row is 1.

I need following output:

---------------------
|ename    | manager |
---------------------
|CTO      | CEO     |
|CFO      | CEO     |
|PM1      | CTO     |
|TL1      | PM1     |
---------------------

The SQL query will be:

SELECT e.name,m.name
FROM employee e, employee m
WHERE e.mid=m.id
AND e.mid NOT NULL;

My problem is, how do I write same query in Symfony/Propel 1.4? I try following

$c = new Criteria();
$c->clearSelectColumns();
$c->addSelectColumn(EmployeePeer::NAME.' as ename');
$c->addSelectColumn(EmployeePeer::NAME.' as manager');
$c->setPrimaryTableName(EmployeePeer::TABLE_NAME);
$c->addJoin(EmployeePeer::MID, EmployeePeer::ID, Criteria::INNER_JOIN);
$c->add(EmployeePeer::MID, NULL, Criteria::EQUAL);

Even I know this query do not make any sense and as per my expectation, I got PropelException.

But self join is one of the common database operation and I’m sure Propel must support that. Can someone please tell how to achieve above requirements in Symfony/Propel 1.4

  • 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-11T11:14:17+00:00Added an answer on June 11, 2026 at 11:14 am

    According to this SQLFiddle, the SQL you want to perform is:

    SELECT e.name as ename, m.name as manager
    FROM employee e
    LEFT JOIN employee m ON e.mid = m.id WHERE e.mid IS NOT NULL;
    

    Like YouthPark, I think addAlias is the solution and I will do something like that:

    $c = new Criteria();
    $c->clearSelectColumns();
    $c->addSelectColumn(EmployeePeer::NAME.' as ename');
    $c->addSelectColumn(EmployeePeer::NAME.' as manager');
    
    $c->addAlias('c2', EmployeePeer::TABLE_NAME);
    
    $c->addJoin(EmployeePeer::ID, EmployeePeer::alias('c2', EmployeePeer::MID), Criteria::LEFT_JOIN);
    
    $c->add(EmployeePeer::MID, Criteria::ISNOTNULL);
    

    I’m not sure about the addSelectColumn part, by the way.

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

Sidebar

Related Questions

The title is pretty self explanatory, but basically I need the table row to
I have a situation where I need to do a self join on a
I've got several function where I need to do a one-to-many join, using count(),
I have a table with navigation that joins back on its self using ParentId.
I don't understand the need for self-joins. Can someone please explain them to me?
I need an algorithm to convert a closed bezier curve (perhaps self-crossing) to a
I need to make an image view animate it's self on and off of
I need to add a rule in the firewall so that my self-hosted http
I need an SSL certificate for a web server. I can generate a self-signed
Rails: I need to set a condition in a has_many that needs the self.id

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.