5

GROUP BY eliminates lines with the same values

 2 years ago
source link: https://www.codesd.com/item/group-by-eliminates-lines-with-the-same-values.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

GROUP BY eliminates lines with the same values

advertisements

for some reason (and I think I know why), when more than one row of $activityday have the same value, the other rows are no longer displayed. I think that it's because of the group by, but I can't be sure.

The $activityday is a number from 1 to 9 that represents an activity on that day. Table venues_activity takes that number and writes the name of the activity, while group by orders the activities in terms of importance.

Is there an alternative to get all of my rows shown? Thank you! :)

SELECT
venues.*,
venues_activity.ACTIVITY_EN
FROM venues
INNER JOIN venues_activity
ON $activityday = venues_activity.ID
LEFT JOIN events
ON events.VENUE_LOCATION = venues.ID
AND start_datetime >= '$DATE_START_SELECTED'
AND end_datetime < '$DATE_END_SELECTED'
where events.VENUE_LOCATION IS NULL
AND VENUE_TYPE='1'
AND $closeday!='Closed'
AND $activityday!='9'
GROUP BY $activityday


I think you want the ORDER BY clause... not the GROUP BY clause.

GROUP BY is intended to do exactly what you describe... group duplicate values into a single row, which is intended to be used in conjunction with aggregate functions, such as SUM, AVG, or COUNT.

ORDER BY simply orders the results.

Tags mysql

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK