0

i'm trying to create a SQL query in Doctrine 2 (Symfony2 Framework), and i need some help. I have two Tables Movie and Person in relation many to many in table Movie_Person.

I want to get a Persons who plays in film. So clear SQL should look like:

SELECT p.* FROM Person p WHERE EXISTS 
                (SELECT m.* FROM Movie_Person m WHERE p.id = m.person_id)

How to write this in Symfony2 + Doctrine2 ?

1 Answer 1

6

Example taken from the docs:

$query = $em->createQuery('SELECT u.id 
                             FROM CmsUser u 
                            WHERE EXISTS (SELECT p.phonenumber 
                                            FROM CmsPhonenumber p 
                                           WHERE p.user = u.id)');
$ids = $query->getResult();

Important note: Remember, this is NOT SQL. It's DQL. The main difference is you operate on objects and properties as opposed to database tables and fields.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.