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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:34:19+00:00 2026-05-31T01:34:19+00:00

I’ve got an SQL query that returns all the rows in one table (country)

  • 0

I’ve got an SQL query that returns all the rows in one table (country) which have a related entry in another table (ducks) but I’m struggling to turn this into DQL. This is a standard one-many relationship as each country can have multiple ducks, I believe it is all set up correctly as I can return ducks within a country and return the country a duck is in using standard code.

The working query is:

SELECT c.* FROM country c 
INNER JOIN ducks d 
ON c.id = d.country_id 
GROUP BY c.country 
ORDER BY c.country ASC

I’ve tried converting this to:

SELECT c FROM WfukDuckBundle:Country c 
INNER JOIN WfukDuckBundle:Ducks d 
ON c.id = d.country_id 
GROUP BY c.country 
ORDER BY c.country ASC

which produces the following error:

[Semantical Error] line 0, col 79 near 'd ON': Error: Identification Variable 
WfukDuckBundle:Ducks used in join path expression but was not defined before. 

I’m quite new to Symfony/Doctrine so I suspect it’s probably something obvious!

I’m using Symfony 2.0.11 with doctrine

Update:
I’ve Also tried:

SELECT c FROM WfukDuckBundle:Country c 
INNER JOIN c.ducks d 
ON c.id = d.country_id 
GROUP BY c.country 
ORDER BY c.country ASC

where ‘ducks’ is defined in the Country class as:

/**
 * @ORM\OneToMany(targetEntity="Ducks", mappedBy="country")
 */
protected $ducks;

public function __construct()
{
    $this->ducks = new ArrayCollection();
}

the definition for country in the ducks class is:

/**
* @ORM\ManyToOne(targetEntity="Country", inversedBy="ducks")
* @ORM\JoinColumn(name="country_id", referencedColumnName="id")
*/
private $country;
  • 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-31T01:34:21+00:00Added an answer on May 31, 2026 at 1:34 am

    Do yourself a favour and use the query builder. Easier to read and update and reuse your queries

    <?php
    
    namespace Vendor\Prefix\Repository;
    
    use Doctrine\ORM\EntityRepository;
    
    class SomeRepository extends EntityRepository
    {
        public function countryDucks()
        {
            // $em is the entity manager
            $qb = $em->createQueryBuilder();
    
            $qb
                ->select('country', 'duck')
                ->from('WfukDuckBundle:Country', 'country')
                ->innerJoin('country.ducks', 'duck')
                ->groupBy('country.country')
                ->orderBy('country.country', 'ASC')
            ;
    
            $query = $qb->getQuery();
    
            // Potential Hydration Modes
            // --------------------------------
            // Doctrine\ORM\Query::HYDRATE_OBJECT
            // Will give you an array of your object entities
            // --------------------------------
            // Doctrine\ORM\Query::HYDRATE_ARRAY 
            // Will give you an array mimicking 
            // your object graph 
            // --------------------------------
    
            return $query->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.