左连接后从表中获取列

时间:2017-04-27 19:03:20

标签: mysql

我必须编辑此查询:

<google-map ...>
  <template is="dom-repeat" items="{{markers}}">
    <google-map-marker 
        latitude="{{item.lat}}" longitude="{{item.lon}}"
        title="{{item.title}}" 
        animation="DROP">
        <h4>{{item.title}}</h4>
    </google-map-marker>
  </template>
</google-map>

我的目标是从参与者表格中选择列,例如participant.first_name&amp; participants.last_name。这是我写的excel导出函数:

$q="select *, (select count(participant_id) 
                from event_tables_seats 
                left join participants on participants.id=event_tables_seats.participant_id 
                where table_id=event_tables.id and participants.status='Active') as participants_in_tables 
    from event_tables 
    where event_id=?";

1 个答案:

答案 0 :(得分:0)

使用连接而不是相关子查询。

SELECT e.*, p.first_name, p.last_name
FROM event_tables AS e
LEFT JOIN event_tables_seats AS s ON e.id = s.table_id
LEFT JOIN participants AS p ON p.id = s.participant_id
WHERE e.event_id = ?
相关问题