我尝试接受此查询:
SELECT
events.ID,
events.EVENT_NAME,
GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
FROM events
INNER JOIN events_music_styles
ON events.ID = events_music_styles.event_id
INNER JOIN music_styles
ON events_music_styles.music_style_id = music_styles.id
GROUP BY events.ID
哪种方法很好,我做了这个:
$id = (int) $_GET['id'];
$data2 = mysql_query("
SELECT
events.ID,
events.EVENT_NAME,
events.SHORT_EVENT_DESC,
events.SMALL_POSTER_URL,
events.start_datetime,
events.VENUE_LOCATION
GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME) AS MUSIC_STYLE_NAME
FROM
venues
INNER JOIN events
ON events.VENUE_LOCATION = venues.ID
INNER JOIN events_music_styles
ON events.ID = events_music_styles.event_id
INNER JOIN music_styles
ON events_music_styles.music_style_id = music_styles.id
WHERE
events.VENUE_LOCATION = venues.ID
AND
WHERE start_datetime >= '$DATE_START_SELECTED'
AND
venues.id = ".$id."
GROUP BY events.start_datetime) or die(mysql_error());
这给了我两个错误:
首先是Group Concat:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近'GROUP_CONCAT(music_styles.MUSIC_STYLE_NAME)AS MUSIC_STYLE_NAME 来自IN'的场地
我知道我主要是从venues
表中检索数据,但是当我加入events
表时这是否重要?
第二个是我拥有的Group by
:
解析错误:语法错误,意外T_ENCAPSED_AND_WHITESPACE, 期待T_STRING或T_VARIABLE或T_NUM_STRING
我以为我关闭了所有字符串所以我不确定为什么会这样做。
答案 0 :(得分:4)
GROUP_CONCAT
之前有一个逗号丢失,这就是全部!
修改强>
第二个也是拼写错误:最后一行中缺少引号,
GROUP BY events.start_datetime) or die(mysql_error());
应该是
GROUP BY events.start_datetime") or die(mysql_error());