简体   繁体   中英

Group By Issue in MySQL Query

Im having trouble with this query:

SELECT a.created_by, 
CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author 
FROM #__content AS a 
LEFT JOIN #__users AS ua ON ua.id = a.created_by 
WHERE a.state='1' 
GROUP BY a.created_by 
ORDER BY author

The results which return are somewhat correct but the issue im having is that its grouping by the ID but its still returning some names repeated (these names are the same but have different ID's).

How can I group these names if they have different ID's?

这是返回代码的示例

Thanks in advance for your help.

Group by Author too

SELECT 
    a.created_by, 
    CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author 
FROM #__content AS a 
LEFT JOIN #__users AS ua ON ua.id = a.created_by 
WHERE a.state='1' 
GROUP BY a.created_by ,author
ORDER BY author

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM