Mario Zelic Mario Zelic -4 years ago 88
MySQL Question

SQL find number of columns

Database schema

Ok, I have this logical scheme about movies, actors, directors, etc. in an SQL database, and I want to create a query that returns me all movies with more than 2 copies.

I've been trying, but I cant get it right, can anybody help me?

Answer Source
SELECT m.title, COUNT(c.mid) FROM movies m, copies c WHERE m.mid = c.mid AND COUNT(c.mid) > 2 GROUP BY m.title; 

This would be achieved using the count function in MySQL and a having clause.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download