0

用户表

id name sex
1  john female
2  bob  male
3  tom  female

日程表

id title
2  work     // bob goes to work
2  shopping 
3  shopping // tom goes to shopping
1  work

Schedule.id 是用户的外键。

我想从用户表中选择有计划去购物的人的行

2  bob male
3  tom female

我该怎么做?

这是我现在的绳子,它可以从日程表中选择行。但我想从用户表中选择行。我认为内部连接很重要,,,,,

$query = $em->createQuery(
SELECT p 
FROM UserBundle:Sche p 
WHERE p.title = 'shopping') ;

$result = $query->getResult(); 
4

1 回答 1

1

尝试这个:

$query = $em->createQuery(
    SELECT a.id, a.name, a.sex, b.title
    FROM User a
    INNER JOIN 
    Schedule b ON a.id = b.id
    WHERE b.title = 'shopping'
);
$result = $query->getResult(); 
于 2013-06-13T15:29:04.353 回答