INNER JOIN中的Sql语句有问题

时间:2014-04-15 03:11:10

标签: sql

继承人我的疑问:

$sql = " `SELECT excelsis_news_events.images.filename as f, excelsis_news_events.event.event_name as en , excelsis_news_events.event.event_date as dd ,excelsis_news_events.event.event_desc as descri ".
                               " FROM excelsis_news_events.images ".
                               " INNER JOIN excelsis_news_events.event ".
                               " WHERE excelsis_news_events.images.event_id = excelsis_news_events.event.event_id ".
                               " GROUP BY excelsis_news_events.event.event_name ".
                               " ORDER BY event_date` ";

它正在检索图像,但问题是每个事件只检索1个图像。我需要使用event_id等于数据库事件中的event_id来获取所有图像。

输出应为

活动名称图片

---------- ---------- event 1 event_id = 1(filenam1.jpg,filenmae2.jpg,filename3.jpg) event 2 event_id = 2(filename1.jpg,filename.2jpg,filename_3.jpg)

但问题是每个事件只检索一个图像。

1 个答案:

答案 0 :(得分:0)

SELECT 
    excelsis_news_events.images.filename as f
    ,excelsis_news_events.event.event_name as en 
    ,excelsis_news_events.event.event_date as dd 
    ,excelsis_news_events.event.event_desc as descri 
FROM 
    excelsis_news_events.event
    INNER JOIN excelsis_news_events.images
        ON excelsis_news_events.images.event_id = excelsis_news_events.event.event_id  
ORDER BY 
    excelsis_news_events.event.event_name
    , excelsis_news_events.event.event_date

如果您正在寻找其他内容,请编辑您的问题,我们需要预期的输出。