lundi 23 novembre 2015

SQLite query for two tables

I have following DB structure:

Schema

Query for DB creation: http://ift.tt/1SV4Gkl

I want to create a query for the result like: id(should be the same as catalog_id from Groups table) -- name -- COUNT(catalog_id) -- catalog_id

Tried to run query:

SELECT name, COUNT(catalog_id), catalog_id
from Catalogs LEFT JOIN Groups on Catalogs.id = Groups.Catalog_id
GROUP BY name
ORDER BY name ASC

but it returns everything except "id" with error in DB Browser for SQLite:

ambiguous column name: id: SELECT id,name, COUNT(catalog_id), catalog_id from Catalogs LEFT JOIN Groups on Catalogs.id = Groups.Catalog_id GROUP BY name ORDER BY name ASC

Can you please give me some advice?

Aucun commentaire:

Enregistrer un commentaire