I am learning MySQL with a sample database.
I have a table “production” where with columns: cd_code, company and year.
I would like to find which company has produced the most cds.
This:
select company, count(cd_code) from production group by company;
Which gives me the companies and how many CDs each has released.
Now from that table with columns (as appeared) company, count(code_cd)
I want to print the company which has the most CDs.
So I want the max of the 2nd column of the 2nd table.
What I am trying is this:
select max(res.cd_code) from (select company, count(cd_code) from production group by company) as res;
And I am getting error 1054:
Unknown column ‘cd_code’ in ‘field list’
What can I do?
Thank you for your time!
You are selecting
company, count(cd_code)inresand hence there is nocd_codein res.If you want to access the count of the
cd_codefromres, then try below: