Hi I'm very new to Stack Overflow so apologies. So currently, I have 2 tables, "albums" and "bands" which have values inside it already.
I want to return only the 'name' column of bands (aka name of the bands) with no albums. So I did the following:-
SELECT bands.name AS 'Band Name'
FROM bands
LEFT JOIN albums ON bands.id = albums.band_id
GROUP BY albums.band_id
HAVING COUNT(albums.id) = 0;
Buttt, I kept on getting this error:
Error Code: 1055. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'record_company.bands.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
So after some digging around, it kinda worked but it returned 2 columns, when I only want the one 'name' column. Here's the query that I used:
SELECT b.name as 'Band Name', a.band_id
FROM bands b
LEFT JOIN albums a ON b.id = a.band_id
GROUP BY a.band_id, b.name
HAVING COUNT(a.band_id) = 0;
And the results: Result of second query
I realized that if I were to use group by, I'd need to group it based on the column selected, otherwise it wont work. I guess my question is is it possible to select A and group by B. Or does it always have to be Select A and group by A. And how do I return that one column only?
Many thanks in advance!